Jump to content
Search Community

Preloading and getting content

un4given test
Moderator Tag

Recommended Posts

Hello,

 

Basically the site I have build consists of two SWF's, the problem I'm having is loading them and displaying the right SWF on the stage.

 

this is the code I am using at he moment.

 

It loads and displays the first swf "city" but Im having trouble removing city and replacing it with "market".

 

Any help would be greatly appreciated, I'm sooo sick of steering at the screen for hours!

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;

var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

queue.append( new SWFLoader("MARKETCS4.swf", {name:"market", estimatedBytes:306176, x:0, autoPlay:false}) );	
queue.append( new SWFLoader("mainCS4.swf", {name:"city", estimatedBytes:1153433.6, container:this, x:0, autoPlay:false}) );

LoaderMax.prioritize("city"); 

queue.load();

function progressHandler(event:LoaderEvent):void {

trace("progress: " + event.target.progress);
}

function completeHandler(event:LoaderEvent):void {

   trace(event.target + " is complete!");
}

function errorHandler(event:LoaderEvent):void {

  trace("error occured with " + event.target + ": " + event.text);

}


addEventListener("MARKET",onMARKET,false, 0, true);


function onMARKET(evt){

var playmarket:ContentDisplay = LoaderMax.getContent("market");

}

Link to comment
Share on other sites

It looks like you figured out how to get the content - you just need to put it onto the stage like this:

 

this.removeChild( LoaderMax.getContent("city") );
this.addChild( LoaderMax.getContent("market") );

 

Since you had set autoPlay:false on the "market" loader, you'd probably want to call play() on its rawContent too, like:

 

LoaderMax.getContent("market").rawContent.play();

Link to comment
Share on other sites

Excellent thanks!!

 

its it working quite nicley apart from when I want to bring the "city" back on to the stage.

 

I used the code below to remove the market and add the city but doesn't work.

this.removeChild( LoaderMax.getContent("market") );
this.addChild( LoaderMax.getContent("city") );

 

 

Again, thank you for the quick response!

 

below is the full code.

 

 


var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

queue.append( new SWFLoader("MARKETCS4.swf", {name:"market", estimatedBytes:306176, x:0, autoPlay:false}) );	
queue.append( new SWFLoader("mainCS4.swf", {name:"city", estimatedBytes:1153433.6/*, container:this*/, x:0, autoPlay:false}) );

LoaderMax.prioritize("city"); 

queue.load();

function progressHandler(event:LoaderEvent):void {

trace("progress: " + event.target.progress);
}

function completeHandler(event:LoaderEvent):void {

var playcity:ContentDisplay = LoaderMax.getContent("city");
this.addChild( LoaderMax.getContent("city") );
trace(event.target + " is complete!");
}

function errorHandler(event:LoaderEvent):void {

  trace("error occured with " + event.target + ": " + event.text);

}


addEventListener("MARKET",onMARKET,false, 0, true);


function onMARKET(evt){

var playmarket:ContentDisplay = LoaderMax.getContent("market");
this.removeChild( LoaderMax.getContent("city") );
this.addChild( LoaderMax.getContent("market") );

}

addEventListener("CITY",onCITY,false, 0, true);


function onCITY(evt){

var playcity:ContentDisplay = LoaderMax.getContent("city");
this.removeChild( LoaderMax.getContent("market") );
this.addChild( LoaderMax.getContent("city") );
}

Link to comment
Share on other sites

Maybe it's because the subloaded swf finished playing and by the time you addChild() again, it is in a different state. Without seeing your swf, FLA, and code in context, it's tough to know for sure. If you want to completely restart and reinitialize your subloaded swf, it would be best to reload it completely, but remember that after the first load, it should be in the browser's cache so it'll load very fast.

 

If you're still having trouble, please post an FLA and any support files so that I can publish the file(s) and see the issue in context. No need to include your production files - just the simplest example isolated in an FLA.

Link to comment
Share on other sites

Cheers!!

 

Works like a charm! oversight on my side.

 

I also have another question. The market SWF that preloads contains files which are brought in via XML. My question is:

 

During the preloading stage, will/does loaderMax preload the xml files?

Link to comment
Share on other sites

I also have another question. The market SWF that preloads contains files which are brought in via XML. My question is:

 

During the preloading stage, will/does loaderMax preload the xml files?

There's a feature in LoaderMax that can accommodate this, yes, as long as the sub-swf is using LoaderMax too. Just make sure that the XMLLoader(s) in the sub-swf have their requireWithRoot set to that swf's root. So your code in the child swf could look like:

 

var loader:XMLLoader = new XMLLoader("file.xml", {requireWithRoot:this.root, name:"xmlData"});
loader.load();

 

When the SWFLoader loads enough of the swf to initialize it, it'll search for any loaders inside of it that had their requireWithRoot set to that child swf's root and if it finds any, it will automatically incorporate their loading progress into the XMLLoader's progress. That way, the COMPLETE event won't be dispatched until the XML loaded inside that child swf too. This is all explained in the ASDocs and on the web site.

 

Does that answer your question?

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