Jump to content


XMLLoader with LoaderMax to Vector

Recommended Posts

I have a XMLLoader loading a XML with the following structure:


 <LoaderMax name="loaderMax" prependURLs="../paginas/" load="false">
	  <SWFLoader url="page1.swf" name="pag1" autoPlay="false"/>
	  <SWFLoader url="page2.swf" name="pag2" autoPlay="false"/>


I want to load automatically all the SWF and track the loader progress and on the loader complete, send all the loaded content to Vector. This Vector will be used along other classes and the content instantiated when needed.



private function startLoaders():void
 loaderXML = new XMLLoader("xml.xml", { name:"book", requireWithRoot:this.root,				estimatedBytes:3000 } );

 loaderMax = new LoaderMax( { name:"loaderMax", onProgress:progressHandlerLoaderMax, onComplete:completeHandlerLoaderMax, onError:errorHandlerLoaderMax } );

private function progressHandlerLoaderMax(evt:LoaderEvent):void
 trace("loaded: " + evt.target.progress);
 this.loadbar.scaleX = evt.target.progress;

private function errorHandlerLoaderMax(evt:LoaderEvent):void
 trace("error loading: " + evt.text);

private function completeHandlerLoaderMax(evt:LoaderEvent):void
 var vector:Vector.<MovieClip> = new Vector.<Class>();
 var xml:XML = loaderXML.getContent("livroConfig");

 numberSWF = xml.child(0).child(0).length();[/indent]

 for (var i:int = 0; i < numberSWF; ++i) [/indent]
	  vector.push(LoaderMax.getLoader("pag" + i).rawContent);

 dispatchEvent(new Event(EventLoadPaginas.LOADCOMPLETE));


This is not working...

What is the best way to accomplish this?


I just need to get all the content from the SWF used anywhere else and call methods inside that SWF.






Thank you!

Link to comment
Share on other sites

on first glance, you have load=false in your xml which will prevent the swfs from loading and thus there won't be any rawContent to push into your vector.

Link to comment
Share on other sites

Another problem I noticed is that your loop starts at 0 but your "pag" names start with 1.


And to get an array of the children of a LoaderMax, you can just use getChildren() which might make it easier for you. For example:


var loaders:Array = LoaderMax.getLoader("loaderMax").getChildren();
for (var i:int = 0; i < loaders.length; i++) {
   myVector[i] = loaders[i];


Just an idea - not necessary to implement.

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.