PDA

View Full Version : Passing an Array from XML to Flash



humbucker
August 5th, 2009, 12:06 PM
Hi,

I'm having difficulties transfering the content of a future array from XML to Flash.
My goal is to be able to set variables in an XML file that will then be used in Flash.
For that purpose, I've started to set my xml like that and it's running ok.



<xml>
<bgGradientColor1>0xd1d1d1</bgGradientColor1>
<bgGradientColor2>0xf2f2f2</bgGradientColor2>
</xml>


But I don't understand how to set my xml to be able to (maybe) create a loop to generate an array variable like this : <br>
public var linkFilesArray=new Array("ABOUT","EVENTS", .....);

Could you teach me how to code the XML the right way and regenerate this arrya in flash then ?

Than you!

MurtenSaerbi
August 5th, 2009, 06:00 PM
I don't quite understand what you are trying to create. You could create an array in the flash and then fill it with variables that you read out of an xml by using the "push" method:




myArray.push(xml.bgGradientColor1);


would fill the first position (which is 0 since arrays are zero-based) with "0xd1d1d1":



trace(myArray[0]); // returns 0xd1d1d1


Is this what you are looking for?

a tadster
August 6th, 2009, 01:32 AM
this is what i do:

<xml>
<navigation>ABOUT,HISTORY,SYNTAX,VISUALIZATION,.AS,EXAMPLES,WR APPERS,COMPONENTS</navigation>
</xml>


in the ActionScript :

...
//after the xml has loaded on a Complete event handler i do:
var theXML:XML = new XML(event.target.data);
var navigationArray:Array = theXML.navigation.split(",");
//so navigationArray[0] is ABOUT
//navigationArray[7] is COMPONENTS
...



hope this helps