Jump to content
GreenSock

toBeConfirmed

LoaderMax - Loading dynamic assets

Recommended Posts

Hello... ok, what i am trying to do is load in assets using Loadermax, I am defining the loaders in the xml file to be created dynamically, but because the url for each loaded asset is dynamic and defined at runtime, i cant seem to find a way to prependURLs from the loader class. is there anyway to do this, or do all the prependURLs have to be defined in the xml and are static?

 

I just wanted to know if this is possible, rather than going through the loaded xml then creating a new loader to load in further assets.

 

Hopefully someone is having a similar problem.

 

thanks

Link to comment
Share on other sites

I'm not sure I understand the question, but you can certainly use prependURLs() after the XML is parsed. Let's assume you have XML like this:






 

You could have ActionScript like this:

var loader:XMLLoader = new XMLLoader("data.xml", {onComplete:completeHandler});
function completeHandler(event:LoaderEvent):void {
   var queue:LoaderMax = LoaderMax.getLoader("myQueue");
   queue.prependURLs("http://www.greensock.com/images/");
   queue.load();
}

Link to comment
Share on other sites

Thank you very much... that's great! I thought that would be the case, I just wondered if the prependURLs could be used before the XML was parsed and just use a single load. Thanks for answering so quickly.

Link to comment
Share on other sites

Sorry, but I still cant get it to work..let me try and explain it a little better and see if you could possibly help..

 

i have my loader :

var loader : LoaderMax = new LoaderMax( {onComplete:loadComplete, onProgress:loadProgress, onError:onError} );

loader.append( new XMLLoader( xmlPath ,{ name : "mainLoader" } ) );

loader.load()

 

xml:

 

 

 

 

I would then like LoaderMax to instantiate these loaders from within the xml and load all the assets before completing, problem is i cant prepend the urls if i set the " load " parameter to true, it also doesnt seem to work if i create a new loader once the xml is parsed and target my "assetLoader" within the xml then activate load. The example you gave me didn't seem work, perhaps as i have different data loaders within the LoaderMax node which stops this from working. Also once the xml is loaded within the example provided, how would i have set the onComplete function, i tried doing this via LoaderMaxVars but it did not work.

 

ideally i would like to pass through the xml and the prepend url, then have each loader within the xml instantiate itself and load all the assets before calling the onComplete function with all the assets ready and loaded.

 

Please let me know if this is not clear enough, i have tried so many different ways but cant seem to work out if this is possible. Obviously i know i can load the xml then cycle through the url nodes then pass these through to another loader instance, but i was hoping that using LoaderMax this could be automated.

 

Thanks, hopefully there is a solution.

Link to comment
Share on other sites

Did you forget to activate the necessary loaders first? You need to do that so that XMLLoader can recognize the various types (, , etc.) Here's some sample code:

 

LoaderMax.activate([imageLoader, CSSLoader]);

var loader : LoaderMax = new LoaderMax( {onComplete:loadComplete, onProgress:loadProgress, onError:onError} );
loader.append( new XMLLoader( xmlPath ,{ name : "mainLoader", onInit:initXMLHandler } ) );
loader.load();

function initXMLHandler(event:LoaderEvent):void {
   var queue:LoaderMax = LoaderMax.getLoader("assetLoader");
   queue.prependURLs("http://www.greensock.com/");
   loader.append(queue); //add it to the main queue so that its onComplete doesn't fire until everything is loaded
}

 

Notice I added an onInit to the XMLLoader so that the initXMLHandler() function gets called as soon as the XML is parsed which will happen BEFORE the XMLLoader (and parent LoaderMax) have completed. Then I prepend the URLs and tuck that whole LoaderMax (from the XML) into the parent LoaderMax which will then load that data, not calling its onComplete until everything has loaded.

 

Cool, huh? :)

Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I have a similar-ish issue here.

 

From the documentation:

INIT events which are dispatched when the loader finishes loading the XML file, parses its contents, and creates any dynamic XML-driven loaders.

 

What I need is some way to get to the XML before it's contents are parsed. I want to do this so I can replace variable scattered throughout the XML.

 

e.g.

 

In my structure.xml

 


>

 

In my locale.xml

 

locale/common/swfs/main_assets.swf

 

I need to access the structure.xml and swap out the mainAssets variable for the mainAssets url contained in the locale.xml.

 

Anything jump to mind?

 

Many thanks,

 

-T.

Link to comment
Share on other sites

I just updated XMLLoader so that it dispatches a new XMLLoader.RAW_LOAD event when the XML has loaded but hasn't been parsed yet. So you'd do this:

 

var loader:XMLLoader = new XMLLoader("data.xml", {onRawLoad:rawLoadHandler});
loader.load();
function rawLoadHandler(event:LoaderEvent):void {
   trace("XML loaded but hasn't been parsed. " + event.data);
   ...do XML alterations here...
}

 

Or if you want to explicitly add the listener, you can of course do this:

loader.addEventListener(XMLLoader.RAW_LOAD, rawLoadHandler);

 

Hope that helps!

Link to comment
Share on other sites

Perfect, thanks Jack. Very much appreciated.

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