Jump to content
Search Community

SWFLoader: Accessing stage before classes?

swiftmend test
Moderator Tag

Recommended Posts

Hi,

 

It seems LoaderMax SWFLoader opens and uses the class file before accessing any actionscript on the loaded swfs timeline - is there a way to force it to load the actionscript on the timeline first?

 

I have an unusual need of this, the default Loader does this so I'm unable to use SWFLoader until I can figure out how to get it to duplicate this behaviour - which I'd much rather do as it allows much cleaner usage.

Link to comment
Share on other sites

It seems LoaderMax SWFLoader opens and uses the class file before accessing any actionscript on the loaded swfs timeline - is there a way to force it to load the actionscript on the timeline first?

 

I have an unusual need of this, the default Loader does this so I'm unable to use SWFLoader until I can figure out how to get it to duplicate this behaviour - which I'd much rather do as it allows much cleaner usage.

 

I'm confused - what do you mean "SWFLoader opens and uses the class file..."? (it doesn't open or use stuff inside the swf)

 

SWFLoader uses a Loader object internally, so I don't quite understand what behavior you're seeing in Adobe's standard Loader that isn't working in SWFLoader. I would, however, recommend that you update to the latest version of LoaderMax because earlier versions waited to add the Loader to the ContentDisplay until after the first frame of the sub-swf loaded, thus making any references to "stage" in the sub-swf null. The latest version has a workaround in place. http://www.LoaderMax.com

Link to comment
Share on other sites

It's strange, anytime I try to use greensock I get a ton of null errors across my SWFs however the standard Loader works fine.

 

I'm loading an object on the timeline that gets referenced straight away and that seems to give errors, I updated to the latest and no help.

 

They're pretty complex SWFs at this point though, so I guess I'll stick with Loader and use SWFLoader in future products.

Link to comment
Share on other sites

I would absolutely LOVE to see an example of the errors you're getting. Again, SWFLoader uses a Loader internally so I'm not sure why it'd work with a standalone Loader but not inside SWFLoader. Are you 100% positive you're using them in identical contexts? I'm confident that if you sent me a sample FLA that generates the error, I can track it down and tell you exactly why. If there is a problem with SWFLoader, I'd sure appreciate the help in identifying it. If it's a problem in your code, maybe I could help shed some light on it for you.

Link to comment
Share on other sites

Aha, I see the problem (at least with the sample you uploaded for me). You coded your subloading swf so that it is dependent upon an ADDED_TO_STAGE event getting dispatched but that's not really a reliable way of initting your app. Technically when a swf is loaded into a Loader that's already in the display list, its "stage" property will already be available when the swf inits, therefore it is already added to the stage (you can test this by doing trace(this.stage) in the constructor of your document class). Your buttons weren't interactive in the sample you provided because your beginClass() was never getting called.

 

It is generally a better practice to do something like this in your constructor:

 

function MyConstructor() {
   if (this.stage == null) {
       this.addEventListener(Event.ADDED_TO_STAGE, init);
   } else {
       init(null);
   }
}

function init(event:Event):void {
   this.removeEventListener(Event.ADDED_TO_STAGE, init);
   ...your init code...
}

 

In any case, I just posted an updated version of SWFLoader that allows any initial ADDED_TO_STAGE events to get pushed through to the sub-swf, so if you update your version of LoaderMax, it should eliminate the problem anyway but I'd still recommend altering your code to follow the recommendation above.

 

If you're still having trouble, please do shoot me a new batch of files that demonstrate the issue(s). According to my tests on your files, though, if you follow my recommendation above it'll fix the problem you were experiencing. And coding it that way isn't a "workaround" for SWFLoader either - it's just a best practice that makes your code run regardless of the environment (if it's on the stage already or not). Even if you don't use LoaderMax at all, I think it'd be wise to implement that code.

 

Hope that helps.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...