Groups | Blog | Home
all groups > flash actionscript > june 2006 >

flash actionscript : Populating and associative array (?)


Guy Verville
6/20/2006 8:08:01 PM
I'm adapting a class explained in 'Flash Application Design Solution". The code
is used for populating a menu system.

In the original code, the menu system array is hardcoded in this fashion:
var MenuData:Array = [{title:"Advanced Flash Interface Design"}, {title:"Flash
3D Cheats Most Wanted"}, {title:"Flash 8 Essentials"}, {title:"Flash Cartoon
Animation"}];

Is this an associative array?

In my code, I would like rather use an XML file to populate MenuData, but
something is missing in my comprehension. The code below doesn't work since
there is not title 'label' associated to my array data.



var MenuXML:XML = new XML();
var MenuData:Array = new Array();
MenuXML.ignoreWhite = true;
MenuXML.onLoad = function()
{
var photos:Array = this.firstChild.childNodes;
for (i = 0; i < photos.length; i++)
{
MenuData[i]=photos[i].attributes.nom;
}
};
MenuXML.load("xml/sympholies.xml");
Guy Verville
6/20/2006 11:38:56 PM
Thank you for answering. My problem resides on the object literals. How to
implement them.

The XML file looks like what is below. My code, for the moment, reads the node
<theme> and the two attributes must be coded as follow:
MenuData[{nom:.....}{chemin:........}]





<photos>
<theme nom="Les affiches au fil des ans" chemin="../images/affichessympholies">
<photo nom="1993_06_19.jpg" titre="1993"/>
<photo nom="1994_06_12.jpg" titre="1994"/>
...
</photos>
Jeckyl
6/21/2006 12:00:00 AM
I don't see anything in there that is a 'title' .. so how do you expect
there to suddenly be a title in your array that you populate from that xml
data?

I think you need to do some thinking about what you want to have happen and
try to implement that first.
--
Jeckyl

Jeckyl
6/21/2006 12:00:00 AM
[quoted text, click to view]

No .. its just an array .. its not associative at all

[quoted text, click to view]

As we have no idea what is in your xml file, we cannot tell what will be in
your array.
--
Jeckyl

Guy Verville
6/21/2006 12:46:48 AM
Guy Verville
6/21/2006 2:58:32 AM
I've found the solution:
MenuData.push({title:photos[i].attributes.nom});
AddThis Social Bookmark Button