I need suggestions about contruct an Array

Hi ,

So sorry that my first post is a question :slight_smile: .

I’m building map in flash , all destinations are declared in a XML document like this :


<destinations>
    <des name="paris" x="200" y="150" />
    <des name="london" x="260" y="180" />
    <des name="berlin" x="340" y="250" />
</destinations>

the XML then supposed to be parsed into an array or each destination is an array with 2 properties x and y . Then draw destination on the map .

My questions is :

  • How to make a multidimention array like this in flash and access it by name ? sorry , I don’t know much about multidimention array , is it could be like this : **destination.paris.x , destination.paris.y ** . I need these because later I will load another XML doc that include route arrays : route1[paris,london] , route2[london,berlin,paris] .

  • The other way is make each destination an array : paris[200,150] , london[260,180] … Do you think this way could slow down the movie (wasting RAM ) , yet it could be easier .


Thank you for reading , I hope someone would help me to contruct this array .

I do appreciate for any help . Bi .

I got this information off of Macromedia by doing a search on “Multidemensional arrays actionscript” in google.

http://www.macromedia.com/support/flash/ts/documents/twodarray.htm

It looks pretty straight forward. Remember that when you place one array in another… it’s mearly a reference to that array.

question though… if you’ve already got the stats in an xml object… why transplant them to an array? You can read all the data from the xml object already.

You could try



destinations=new Array()
destinations["paris"]=[200,150]
destinations["london"]=[260,180]
destinations["berlin"]=[340,250]


to retrieve the x coord for paris use
destinations[“paris”][0]

to retrieve the y coord for paris use
destinations[“paris”][1]

:slight_smile: thank you so much , both of you with your help , I finally find the way out . I choose jsk’s method .


*Originally posted by david *
**question though… if you’ve already got the stats in an xml object… why transplant them to an array? You can read all the data from the xml object already. **

Please correct me if I’m wrong or my method is not a good method :

  • I choose jsk’s because I have another XML doc like this

<route>
	<name>Explore the Erope</name>
	<description>aaaldsakfj lkdsjf lskj lsakdjf lksdjf lksajd</description>
	<destinations>paris,london,berlin</destination>
	<imagepath>images/g.jpg</imagepath>
</route>
..... <route>.....</route>

… it will be parsed to single record and showed in one box . the destinations text will be split to an array and then reference to the destination locations XML to draw on the map . The destination locations XML will be loaded at the main movie as Global reference for many records to use . If I don’t contruct this Global array , I’ll have to parse and search for location of each destination whenever load each route .

And because in the record

<destinations>paris,london,berlin</destination>

is just a text so I need the destination location array can be referenced by name .


Thank you again , and please suggest me more if it can be improved .

Sorry about my English :slight_smile:

english… no problem… we get a lot of people here who have trouble with that crazy language. :slight_smile:

I guess I would have writen the xml a little different, something like.


<route>
  <name>Explore the Erope</name>
  <description>aaaldsakfj lkdsjf lskj lsakdjf lksdjf </description>
  <destination name="paris"xLoc="123" yLoc="420"</destination>
  <destination name="london" xLoc="34" yLoc="50"</destination>
  <destination name="berlin" xLoc="175" yLoc="54"</destination>
  <imagepath>images/g.jpg</imagepath>
</route>

Flash parses through “attributes” of xml nodes VERY quickly. So fast that you would probebly not notice the difference between it and the array method you chose.

From that set up it’s really just a matter of looking for the node with the right name, and then finding out what it’s xLoc and yLoc are. I’ve been working on a solitare game for weeks now and it’s really hard. I have offset attributes, location attributes, depth attributes…and that’s just for location of the card… let alone things like the suit, color, and value of the card.

Thanks alot for all your help :slight_smile: I really do .

Finally I’ve finished the parse code procedure , now I’m trying to solve the problem with route drawing , it’s still a mess though and I hope i’ll not bother you next time :wink: , hope so

Have a good day .