Jump to content
Search Community

Loading external SWFs from XML file

neuralism test
Moderator Tag

Recommended Posts

Hi All,

 

My preloader runs a little funny and is not progressing as it should.

I'm currently loading an xml file which contains a list of other SWFs for the preloader to load.

It updates the LoaderMax object by appending new SWFLoaders once the xml has been loaded.

 

import com.greensock.loading.LoaderMax;
import com.greensock.loading.XMLLoader;
import com.greensock.loading.SWFLoader;

public var loader:LoaderMax = new LoaderMax( { onProgress: progressHandler, onComplete: completeHandler } );

public function init():void
{
loader.append(new XMLLoader("data.xml", { name: "data_xml", onComplete: updateLoader } );
loader.load();
}

public function updateLoader(event:LoaderEvent):void
{	
var xml:XMLList = XMLList(loader.getContent("data_xml"));	

for (var i:int = 0; i < xml.loadlist.length(); i++) 
{
	loader.append(new SWFLoader(xml.loadlist.item[i], { name: "item" + i } ));
}
}

 

I know what I'm doing doesn't seem right, can't expect the preloader to predict the files in the xml even before the it has been loaded

How should I go about compacting this whole process into 1 preloader? It is going to be dynamic so the external swfs will change over time.

 

XML file example:

 

<?xml version="1.0" encoding="utf-8"?>

item0.swf
item1.swf
item2.swf
item3.swf
item4.swf
item5.swf

 

Thanks in advance!

Link to comment
Share on other sites

You could take advantage of XMLLoader's built-in ability to integrate LoaderMax-related nodes that it finds inside the XML. For example, if your XML looked like this:

 










 

Then XMLoader would automatically create all those SWFLoader instances for you AND load them AND integrate their progress into the XMLLoader's progress (once it determines their file sizes of course, which you could make faster by defining estimatedBytes for each one).

 

You don't have to do it that way, though - your code should work fine but either way, you should set the estimatedBytes of your XMLLoader as if it included ALL of the nested SWFLoaders. That will help prevent the shooting forward and then falling back of the progress values as the new loaders get added.

 

Make sure you read http://www.greensock.com/loadermax-tips/ because there are some tips in there that directly relate to this.

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