Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-01-2012, 04:23 AM   #1
Mr.Print
Registered User
 
Join Date: Mar 2012
Posts: 4
Default Custom preloader working with 2 frames

Have custom AS3 preloader which displays a progress bar using swc file and have added -frame start "Application" to the actionscript compiler additional compiler arguments. Preloader works, however Application class never loads.

Code:
package
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;	
	import flash.utils.getDefinitionByName;
	
	[SWF(scriptRecursionLimit="5000",
		 scriptTimeLimit="30",
		 frameRate="24", 
		 backgroundColor="0x606060",
		 pageTitle="AS3 Preloader Example")]
	[Frame(factoryClass="com.myproject.preloader.CustomPreloaderExample")]
	public class AS3ProjectPreloader extends Sprite
	{
		private function swfLoadedHandler(event:Event):void
{
    startApp();
}		
		public function AS3ProjectPreloader()
		{
			super();			
			addEventListener( Event.ADDED_TO_STAGE, _init, false, 0, true );
		}
			private function startApp():void
{
                  var AppClass:Class = getDefinitionByName("Application")  as Class;
		}
	}
}
New to Flash Builder and hoping someone can point me in the correct direction. Thanks in advance for your time.
Mr.Print is offline   Reply With Quote
Old 05-01-2012, 01:21 PM   #2
tadster
tadster
 
tadster's Avatar
 
Join Date: Feb 2009
Location: Texas
Posts: 2,111
Default

Which class is supposed to be the actual preloader?
AS3ProjectPreloader or CustomPreloaderExample?

The actual preloader would be the factory class.

In it, something like this will be the end result:
ActionScript Code:
public function CustomPreloaderExample() {      addEventListener(Event.ENTER_FRAME, doLoad); } private function doLoad(e:Event):void {   if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal) {                         removeEventListener(Event.ENTER_FRAME, doLoad);                         var c:Class = getDefinitionByName("packageName::Application") as Class; //Application should be the class that defined this preloader as the factory class at top.         var s:Sprite = new c();         addChild(s);                     } }
__________________
www.actiontad.com - ActionScript and JavaScript sitting in a tree...
tadster is offline   Reply With Quote
Old 05-01-2012, 03:14 PM   #3
Mr.Print
Registered User
 
Join Date: Mar 2012
Posts: 4
Default

Quote:
Originally Posted by tadster View Post
Which class is supposed to be the actual preloader?
AS3ProjectPreloader or CustomPreloaderExample?

The actual preloader would be the factory class.

In it, something like this will be the end result:
ActionScript Code:
public function CustomPreloaderExample() {      addEventListener(Event.ENTER_FRAME, doLoad); } private function doLoad(e:Event):void {   if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal) {                         removeEventListener(Event.ENTER_FRAME, doLoad);                         var c:Class = getDefinitionByName("packageName::Application") as Class; //Application should be the class that defined this preloader as the factory class at top.         var s:Sprite = new c();         addChild(s);                     } }
tadster,
The AS3ProjectPreloader is the actual Preloader class. Appreciate you giving up your time to help. Being new to Flash Builder my understanding is limited. I ran into one problem with your suggested code.
<code>
private function doLoad(e:Event):void { .....
</code>
"1013: The private attribute may be used only on class definitions."

I've ran into this several times in the past and have limited knowledge on how to correct.

Thanks for your patience and thanks again for the help and any further direction you provide.
Mr.Print is offline   Reply With Quote
Old 05-02-2012, 12:00 PM   #4
tadster
tadster
 
tadster's Avatar
 
Join Date: Feb 2009
Location: Texas
Posts: 2,111
Default

The original code you posted, sure looks like a class. But the AS3ProjectPreloader class, as you have it posted in your original post, would not work at all. There's no _init method and the AppClass is never added to the display.

As for the error, just as in your original code, to use the private declaration, the code needs to be in a package and a member of a class, just like the startApp method or swfLoadedHandler method of your previous post.

Can you post the code as you have it now?
__________________
www.actiontad.com - ActionScript and JavaScript sitting in a tree...
tadster is offline   Reply With Quote
Old 05-04-2012, 04:26 AM   #5
Mr.Print
Registered User
 
Join Date: Mar 2012
Posts: 4
Default

Quote:
Originally Posted by tadster View Post
The original code you posted, sure looks like a class. But the AS3ProjectPreloader class, as you have it posted in your original post, would not work at all. There's no _init method and the AppClass is never added to the display.

As for the error, just as in your original code, to use the private declaration, the code needs to be in a package and a member of a class, just like the startApp method or swfLoadedHandler method of your previous post.

Can you post the code as you have it now?
Posting code as I have now. (If I've used the wrong class it is due to my limited knowledge)

<code>
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.getDefinitionByName;

[SWF(scriptRecursionLimit="5000",
scriptTimeLimit="30",
frameRate="24",
backgroundColor="0x606060",
pageTitle="Design")]
[Frame(factoryClass="com.preloader.CustomPreloader" )]
public class Main extends Sprite
{
public function Main() {
addEventListener(Event.ENTER_FRAME, doLoad);
}
private function doLoad(e:Event):void {
if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal) {

removeEventListener(Event.ENTER_FRAME, doLoad);

var c:Class = getDefinitionByName("Card") as Class;
//Application should be the class that defined this preloader as the factory class at top.
var s:Sprite = new c();
addChild(s);
}
}
}
}
</code>

Flash Builder display no errors currently, however at run time I get:
An ActionScript error occurred
ReferenceError: Error #1065: Variable Card is not defined.
at global/flash.utils.getefinitonByName()
at Main/doload()/user/"name"/Documents/ Adobe Flash Builder 4.5/Main/scr/Main.as:27

Last edited by Mr.Print; 05-04-2012 at 04:29 AM. Reason: spelling
Mr.Print is offline   Reply With Quote
Old 05-04-2012, 10:40 PM   #6
tadster
tadster
 
tadster's Avatar
 
Join Date: Feb 2009
Location: Texas
Posts: 2,111
Default

ok, here is some sample code for you, you still have things mixed up, the loading code goes in the factory class, not in the main.
ActionScript Code:
// ... PreLoader.as package  theFolderItsIn  //the package name IS the folder its in {    public class PreLoader extends Sprite    {            public function PreLoader() {                  addEventListener(Event.ENTER_FRAME, doLoad);            }            private function doLoad(e:Event):void {                   if(this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal) {                           removeEventListener(Event.ENTER_FRAME, doLoad);                           finish();                   }            }            private function finish():void {                   var c:Class = getDefinitionByName("theFolderItsIn::MainClass") as Class;                   var s:Sprite = new c();                   addChild(s);            }    } } // ....   MainClass.as   - in the same folder/package as PreLoader.as package theFolderItsIn {      [Frame(factoryClass="theFolderItsIn.PreLoader")]      public class MainClass extends Sprite      {                public function MainClass() {                     //main app code goes here                    //this class needs to know nothing about the preloader.                    //however it should wait to be added to the stage before doing much of anything                     addEventListener(Event.ADDED_TO_STAGE, ini);                }                private function ini(e:Event):void {                   removeEventListener(Event.ADDED_TO_STAGE, ini);                                       //... main app code...                }      } }

The class that gets compiled is the MainClass.
__________________
www.actiontad.com - ActionScript and JavaScript sitting in a tree...

Last edited by tadster; 05-04-2012 at 10:44 PM.
tadster is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:25 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.