Jump to content
Search Community

adding an image loader from an xml list

casdadog test
Moderator Tag

Recommended Posts

Hi

 

I'm pretty new to this xml stuff and LoaderMax although I've been using tween lite for years and love it!

 

I'm trying to load in an xml file and to use the various data within it to populate a series of panels with images and text. I want to create 2 'main' panels, one with 7 and one with 8 'sub' panels within them.

 

I've loaded my xml and extracted various tags and placed them in XMLLists. the code below does this for me. I've set up variable outside the function to hold the xml data.

 

 function xmlLoaded(e:LoaderEvent):void
     {
        trace("Loaded");
        mainMenuImages = xml.content.mainMenu.panel.ImageLoader;
	 mainMenuText = xml.content.mainMenu.panel.showText.@textToShow;
	 trace(mainMenuImages);
	 trace(mainMenuText);
	trace("\n main menu images.length()  = " + mainMenuImages.length());
	wh1Images = xml.content.wh1.panel.@ImageLoader;
	wh1Text = xml.content.wh1.panel.showText.@textToShow;
	 trace(wh1Images);
	 trace(wh1Text);
	trace("\n whats hot 1 images.length()  = " + wh1Images.length());
        //showImage(mainMenuContainer, mainMenuImages, index);
	 showImage();
     }

 

my trace (for MainMenuImages) give me:

 

 

How can I then use this information to load (ImageLoader?) all of the the images with their attributes and place them in a single container and display on stage?

 

I'd really appreciate some help as I'm going round in circles!!

 

Thank you.

 

Cas

Link to comment
Share on other sites

Hi,

 

Here is a great tutorial on XMLLoader basics:

 

http://www.snorkl.tv/2011/08/loading-im ... xmlloader/

 

It will show you exactly how to load and display ImageLoader content from an xml file.

 

Unfortunately, (no fault of greensock) it is impossible to specify the container attribute in the xml. The trick is to use an onChildComplete handler function to place the loaded asset where you want it to go.

 

Although not covered in the tutorial, you can put the description text directly in each ImageLoader like so:

 

 

to retrieve the text:

 

trace( LoaderMax.getLoader("2").vars.descriptionText )

 

lots of handy tips in the docs: http://www.greensock.com/as/docs/tween/ ... oader.html

Link to comment
Share on other sites

Hi Carl

 

Thanks for your reply, it has cleared things up a bit for me. Can I use the var in my XML, e.g. Container = mainmenu to target the container clip I want to add the images into? If so how do I do this? I think I've tried before but can't get flash to recognise this as a movie clip name.

 

Hope that makes sense?

 

Thanks in advance.

 

Cas

Link to comment
Share on other sites

Sorry, but isn't this the same question I answered above?

 

Unfortunately, (no fault of greensock) it is impossible to specify the container attribute in the xml. 

 

am I missing something?

 

 

feel free to elaborate.

 

carl

Link to comment
Share on other sites

Hi Carl

 

Sorry I wasn't very clear. In your answer below where I use the handler....

 

Unfortunately, (no fault of greensock) it is impossible to specify the container attribute in the xml. The trick is to use an onChildComplete handler function to place the loaded asset where you want it to go.

 

What I want to do when using the handler above is to add some of the loaded images into one container and others into a different container. Ideally I'd like to specify a value in the XML that can be used to reference a container that I have already set up and added to the stage.

 

Would I be right in thinking that I would need to check the variable in the XML eg.

 

If the XML var is mainMenu then add child to mainMenu

 

If the XML var is otherContainer then...

 

Or Am I able to do this another, shorter way as I will have up to 6 containers to add a range of imageloaders into?

 

Hope this is clearer, it's late in the uk and I've had a long day :)

 

Thank you for your time so far.

 

Cas

Link to comment
Share on other sites

ah, that makes a ton of sense. thanks for clearing it up.

 

yes, your approach is sound and I can't think of a better way.

 

even though you have 6 container options a switch statement should make it pretty straightforward

 

function onChildCompleteHandler(e:LoaderEvent):void{

var myContainer:MovieClip //or sprite or whatever

switch (e.target.vars.container) {

case "panel8" :
myContainer = this.panel8_mc
break;

case "footer" : 
myContainer = this.footer_mc
break;

//etc etc
}

//now that we know what myContainer is we can add the content of the loader to it
myContainer.addChild(e.target.content);

}

 

the above code isn't tested but should be pretty close

 

let me know if you need more help.

Link to comment
Share on other sites

Hi Carl

 

That's fixed it for me alright. Thank you so much. My issue has been that I wasn't sure how to reference an object that was already set up using a variable and you've helped me understand how to do it.

 

Just one more thing... apart from the initial load and set up is it possible to reference the vars again?

 

e.g.

 

function linkOut(e:MouseEvent):void {
LoaderMax.getContent(e.target.parent.vars.panelLink)
var targetURL:URLRequest = new URLRequest(the link value that is stored in the panelLink var);
navigateToURL(targetURL, "_self");
trace("clicked");
}

 

with panelLink holding the url I want to link to when a user clicks on a clip.

 

Thanks again.

 

Cas

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