Jump to content
Search Community

SWFLoader Inside ImageLoader

alflasy test
Moderator Tag

Recommended Posts

So, here I am back with another task which I can do it with URLLoader but want to if LoaderMax can handle it.

 

I have series of imageLoader in LoaderMax and some ImageLoader may have related swf that can be loaded on demand. I thinking of XML like below.

 

<LoaderMax load=true>

<ImageLoader prependURL='media/'></ImageLoader>

<ImageLoader>

<SWFLoader load=false url='mySWF.swf'></SWFLoader>

</ImageLoader>

<ImageLoader></ImageLoader>

<ImageLoader></ImageLoader>

</LoaderMax>

 

Is that possibel?

Link to comment
Share on other sites

Yes, you can do that.

 

One thing to note though is if you want one of the nested ImageLoaders to load on demand and not initially you will have to set its paused property to true.

 

See the xml example below:

 

 

<LoaderMax name="images" prependURLs = "images/" load="true" maxConnections="1" >
<ImageLoader name="whale1" url="whale.png" estimatedBytes="60000" x="0" y="0">
<!-- set lobsters paused = true -->
<ImageLoader name="lobster2" url="lobster.png"  paused="true" estimatedBytes="94000" x="0" y="200"/>
<ImageLoader name="crab3" url="crab.png" estimatedBytes="94000" x="320" y="0"/>
<ImageLoader name="bird4" url="bird.png" estimatedBytes="60000" x="320" y="200"/>
</ImageLoader>
</LoaderMax>

 

Setting paused = true for the lobster ImageLoader still allows the ImageLoader to get created and be associated with the parent LoaderMax. Since it is paused, the parent LoaderMax will still fire its ON_COMPLETE event when all the other un-paused loaders finish loading.

Link to comment
Share on other sites

Thanks again Carl,

But still don't understand that how the onprogress and Oncomplete event will be triggered when the user click to open that SWF.

 

We already have two seperate onComplete Event. One for LoaderMax onComplete and other for ImageLoader onChildComplete then the SWF is the GrandChild of LoaderMax. How to get the onprogress and onComplete event for GrandChild

Link to comment
Share on other sites

It gets a little tricky, but since the paused loader never loaded when the XMLLoader was loading all of its child assets you have to find the name of the nested and paused loader, and then assign its own eventListeners for its PROGRESS and COMPLETE events. The good news is you can just re-use your existing event listeners.

 

considering the xml I'm working with

 

 

<data>
<LoaderMax name="images" prependURLs = "images/" load="true" maxConnections="1" >
<ImageLoader name="whale1" url="whale.png" estimatedBytes="60000" x="0" y="0">
<!-- set lobsters paused = true -->
<ImageLoader name="lobster" id="lobster" url="lobster.png" estimatedBytes="94000" x="0" y="200" paused="true"/>
<ImageLoader name="crab2" url="crab.png" estimatedBytes="94000" x="320" y="0"/>
<ImageLoader name="bird4" url="bird.png" estimatedBytes="60000" x="320" y="200"/>
</ImageLoader>
</LoaderMax>
</data>

 

I have made another demo that allows you to click on any image. A function runs which looks to see if that image's loader has any rawXML. With my xml only the whale has nested loaders and thus its the only one that has any children in its rawXML.

 

When nested xml data is detected on click of the whale, my function grabs the name attribute from the first nested ImageLoader node and then uses LoaderMax's getLoader() method to find the ImageLoader object that was created.

 

I then assign a COMPLETE event listener and load the lobster image.

 

demo here: http://www.snorkl.tv/dev/nestedLoader/

 

the code that detects that the clicked image has rawXML, finds the loader, assigns the COMPLETE listener and loads it looks like this:

 

 

function checkForChildLoaders(e:MouseEvent): void{
//trace(e.target.loader.vars.rawXML.children().length());
if(e.target.loader.vars.rawXML.children().length() > 0){
trace("has rawXML");
trace("name of first child loader =t " + e.target.loader.vars.rawXML[0].ImageLoader[0].@name)
//find name attribute of the first ImageLoader nested inside the whale ImageLoader node (lobster)
var myChildLoaderName:String = e.target.loader.vars.rawXML[0].ImageLoader[0].@name;
var myChildLoader = LoaderMax.getLoader(myChildLoaderName);
//assign a COMPLETE listener
myChildLoader.addEventListener(LoaderEvent.COMPLETE, childCompleteHandler);
myChildLoader.load();
}else{
trace("no rawXML");
}
}

 

cs5 files attached

loadNestedPausedLoader_CS5.zip

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