Jump to content
Search Community

Load XML and a variable number of images in that XML?

jguthrie test
Moderator Tag

Recommended Posts

I am trying to load an XML file using LoaderMax, then loop through the XML, loading a variable number of images whose path/name are in the XML file. I have looked into the method described in point #3 here but it seems as if you need to know the 'name' of the image before you load it to access it on the onComplete method. Can this be done? Is there a name attribute in a LoaderEvent that I am not seeing?

 

In the end, I want each image to be added to flash as they are loaded and not have to wait until all of them are loaded...

 

Thanks!

Link to comment
Share on other sites

It would probably help if you posted some of your code. You don't need to name each loader - that's an optional convenience. You can get any loader by URL too. So something like LoaderMax.getLoader("http://www.greensock.com/img/1.jpg") will work too.

 

If you want to get notified each time a loader in the queue completes, simply listen for the CHILD_COMPLETE events (or use the onChildComplete shortcut in the vars object). Like this:

 

var queue:LoaderMax = new LoaderMax({onChildComplete:childCompleteHandler});
queue.append( ... );
...
queue.load();

function childCompleteHandler(event:LoaderEvent):void {
   trace(event.target + " completed!");
}

 

If you have 10 ImageLoaders in the queue, you'd see that trace() 10 times.

 

Does that help? If not, please post your code so we can see how you're structuring things.

Link to comment
Share on other sites

Yes that is right along the lines of what I want to do, thanks! I knew it had to be some sort of event I was missing...

 

Here is my code. I dont know if this is the best way to NOT add the XML to my container movieclip ... I need the if statement there so that it doesnt throw an error when it tries to do so...

 

private var _loaderMax:XMLLoader;

private function loadMyXML():void {
		LoaderMax.activate([imageLoader]); //only necessary once - allows XMLLoader to recognize ImageLoader nodes inside the XML

		_loaderMax = new XMLLoader("images.xml", {onComplete:completeHandler, onError:errorHandler,onChildComplete:childCompleteHandler});
		//_loaderMax.append( new XMLLoader("images.xml", {name:"imagesXML"}) );
		_loaderMax.load();

	}

	private function childCompleteHandler(event:LoaderEvent):void {
		 trace(event.target + " completed!");
		 if (event.target.name != 'imagesXML') {
		 	_sImage_mc.addChild(event.target.content);
		 }
	}

my xml:

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










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