Jump to content
Search Community

how to access loaded data from a different container?

sbarret test
Moderator Tag

Recommended Posts

Hello all

 

Inside my app structure, LoaderMax will load a swf in a different container from the one I have the LoaderMax code.

 

This other container, a MovieClip, also has a class file with some code.

 

The question that I have is - how should I access the loaded content from this other MovieClip, once the loading is done?

 

I thought about creating a ContentDisplay variable, and assigning the loaded one there, but it won't work

Example - let's say the swf was loaded into this container, and I know its name is "background"

var loadedContent:ContentDisplay = getChildByName("background")

nope, won't work - implicit coercion error.

 

I know that the "background" ContentDisplay object is there, but I don't know how to keep referencing it in my code.

Any ideas?

Link to comment
Share on other sites

If I understood your question correctly, the way you're structuring things sounds a bit clumsy. In object-oriented programming, it's generally a good idea to modularize things as much as possible and limit interdependencies. In your description, it sounds like object A is loading object B and placing it inside object C, but object C relies on object B even though it has no awareness of it and it's not in charge of loading it. If object A is in charge of loading the content that object C needs, then object C should be making a request to object A for that info rather than trying to self-discover it. After all, how would it know when it arrived or if it has even started loading yet, etc.?

 

Maybe object A has a "swfLoader" property that it exposes to the outside world. Then object C could get at that whenever it needs to, and it could addEventListener() to discover when it has loaded or it could check its "status" property to see if it has already loaded. See what I mean? Object C is going right to the source - the guy in charge of loading what it needs (object A).

 

Then, in object C, it'd be as simple as:

 

if (myObjectA.swfLoader.status == LoaderStatus.COMPLETED) {
   onSWFLoadComplete(null);
} else {
   myObjectA.swfLoader.addEventListener(LoaderEvent.COMPLETE, onSWFLoadComplete);
}

function onSWFLoadComplete(event:LoaderEvent):void {
   if (event != null) {
       event.target.removeEventListener(event.type, onSWFLoadComplete);
   }
   var myContent:ContentDisplay = myObjectA.content;
   //and so on...
}

 

Also, just for the record, you can use LoaderMax's static getLoader() or getContent() methods to get any loader or content anytime. Like LoaderMax.getLoader("myLoaderNameOrURL");

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...