Jump to content
Search Community

XML Loading attributes

Anks test
Moderator Tag

Recommended Posts

I'm trying to figure out how I can assign my attributes(ex. des="") inside my xml document to movieclips/textfields. Right now I've managed to get the images loaded in and I've assigned them to movieclips as you can see below. But I'm having issues with understanding how to pass in the other attributes assigned to that imageloader. Also I'm not entirely sure I am doing the whole "loading the XML" thing properly but any suggestions to clean my code up would be greatly appreciated.

 

Here is my current XML:

<?xml version="1.0" encoding="iso-8859-1"?> 














 

Here is my code where I am adding my XMLLoader and loading the pictures.

private function init()
	{
		queue = new XMLLoader("xml/port.xml",{name:"xmlDoc", maxConnections:1, estimatedBytes:5000, onComplete:queueCompleteHandler, onChildComplete:imageCompleteHandler});

		queue.load();
	}

	private function queueCompleteHandler(e:LoaderEvent):void
	{
		trace("evertything loaded");
		addScroller();
		hoverCheck();
	}

	private function imageCompleteHandler(e:LoaderEvent):void
	{
		loadedImage = e.target.content as ContentDisplay;
		loadedImage.alpha = 0;

		thumbHolder = new ThumbHolder();
		portArray[imageCounter] = thumbHolder;

		mainHolder.addChild(thumbHolder);
		thumbHolder.imgPre.alpha = .8;
		thumbHolder.x = imageCounter * 210;
		loadedImage.x = -97.5;
		loadedImage.y = -60;
		thumbHolder.imgPre.addChild(loadedImage);

		border = new Border();
		thumbHolder.addChild(border);

		portArray[imageCounter].name = "thumbHolder"+imageCounter;
		portArray.push(thumbHolder);

		TweenMax.from(thumbHolder, 1, {x:-200, alpha:0,rotation:90, ease:Back.easeIn});
		TweenMax.to(thumbHolder, 1, {dropShadowFilter:{color:0x000000, alpha:1, blurX:10, blurY:10, distance:1}});
		TweenMax.to(loadedImage, 1, {alpha:1, ease:Sine.easeInOut});
		imageCounter++;
	}

 

Thanks in advance! Any help would be greatly appreciated!

Link to comment
Share on other sites

looks like you have things put together nicely.

 

here is how you would access the des attriubute from your nodes:

   private function imageCompleteHandler(e:LoaderEvent):void
     {
           // get the des attribute from the loader that fired the onChildComplete event
            trace(e.target.vars.des);       

            // + all your other stuff

     }

 

thanks for taking the time to make your question so clear!

Link to comment
Share on other sites

Thanks so much!

 

I have another question. If I were to switch my xml format to look like this:

<?xml version="1.0" encoding="iso-8859-1"?> 
















 

What would I have to change in order to access the attributes when they are now inside a LoaderMax tag?

 

I've tried this: "loadedImage = e.target.content.LoaderMax as ContentDisplay;" But its just throwing errors for me. Assuming something to do with LoaderMax and ContentDisplay?

Link to comment
Share on other sites

the problem that you are going to encounter is that the LoaderMax node itself is a child of the XMLLoader as well as all the ImageLoaders.

 

so your onChildComplete event will fire when all the ImageLoaders inside your LoaderMax node complete. so what happens is your imageCompleteHandler is trying process a LoaderMax.

 

you don't have to change the way you access the des attribute at all. you just need to make sure the the LoaderMax isn't being processed inside imageCompleteHandler like so:

 


function imageCompleteHandler(event:LoaderEvent):void
{
       //make sure the loader firing the even is ImageLoader and NOT LoaderMax
if(event.target is ImageLoader){

trace("some image loaded " + event.target.vars.des);
trace(event.target.content);

var loadedImage:ContentDisplay = event.target.content as ContentDisplay;

addChild(loadedImage);

loadedImage.scaleX = loadedImage.scaleY = .5;

TweenLite.to(loadedImage, 1, {alpha:1});

}





}

 

the above is source from my test file. all the code is not exactly what you will use. just focus on the

 

if(event.target is ImageLoader) part.

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