Can anyone give me a little run down on calling information from an array from other movie clips and such. Please include the basics of creating an array for any Newbies who might want to read this.\r\rThanks ahead of time.\r\r* edited to fix typo in subject*
myArray=[“itemone”,“itemtwo”,“itemthree”,“itemfour”];\r\rtrace(myArray[2]);\r\rwill yield:\r\ritemthree\r\rwhat?! three? yes, because arrays are zero based, ie the first item is item 0. you can think of it as representing an offset from the beginning, so myArray[1] means 1 item from the beginning. this can be useful in for loops:\r\rfor(j=0;j<myArray.length;j++){\r        text += myArray[j] ;\r}\r\rtrace(text);\r\rwill yield:\r\ritemoneitemtwoitemthreeitemfour\r\ryou might say: text += myArray[j]+" "; to get some spaces.\r\rerm, anything not clear? oh, how about associative arrays, which in flash are actually objects:\r\rmyObject = new Object();\rmyObject[“harry”] = “hairy”;\rmyObject[“jane”] = “plain”;\rmyObject[“chuck”] = “wood”;\rmyObject[“dick”] = “use your imagination you dirty bugger”;\r\rthen\r\rtrace(myObject[“jane”]);\r\ryields:\r\rplain\r\raside from for loops, i find arrays most useful when i want one action to accomplish many tasks. say the variable “z” is set (somehow), i can say:\r\rtrace(myObject[z]);\r\rand get different results based on what “z” equals. note the lack of quotes as compared to the previous trace.\r\rthe next thing would be multidimensional arrays. a big mouthful that means an array of arrays, like so:\r\rmyMultiArray = new Object();\rmyMultiArray[“jaguar”] = [“red”,“fast”,“expensive”];\rmyMultiArray[“ford”] = [“blue”,“medium”,“cheap”];\rmyMultiArray[“hyundai”] = [“yellow”,“molasses”,“worthless”];\r\rthen\r\rtrace(myMultiArray[“ford”][2]);\r\ryields:\r\rcheap\r\rit’s like having your own mini database. in fact, that’s exactly what it is.\r\ranything else?
thanks\r\rin addition… this is my problem specificaly.\rI’m looking to have a movie clip which constantly updates it’s own _y possition based upon a variable which I change through out my movie. I have 30 of these movie clips which all need their own variable for _y to read from.\rAlso I’ve heard that you can name your array elements instead of using the numbers.\rSo this is what I did. I set up an array called “stack” which has stack [a], stack ** ect, all the way up to [dd].\rI am attempting to have script send a value of 20 to stack[a]\rhow would I have it send that data to there, AND, how would I call upon that data again.\r\rMaybe it’s obvious, but the only discriptions I find on arrays talk about entering strings into them… I dont need strings I need numbers and they don’t seem to be working properly.\r\rAny help is apprecia**
Buy Moocks book, everything is in there \r(sorry, lazy today…)
umm… No …please explain it. \r\rI have spent far too much on books. I even have one that details arrays… I still don’t understand them.\rI do however understand laziness so you’re forgiven Eyez…
ok I figured out what I was doing wrong there. Much thanks for the help. \rnow can someone give me a basic run down on arrays within arrays?
hmm, i wonder why my posts get scrunched like that. here’s what the bottom was meant to look like.\r\rmultidimensional arrays. a big mouthful that means an array of arrays, like so: \r\rmyMultiArray = new Object();\rmyMultiArray[“jaguar”] = [“red”,“fast”,“expensive”];\rmyMultiArray[“ford”] = [“blue”,“medium”,“cheap”];\rmyMultiArray[“hyundai”] = [“yellow”,“molasses”,“worthless”]; \r\rthen\r\rtrace(myMultiArray[“ford”][2]);\r\ryields:\r\rcheap\r\rit’s like having your own mini database. in fact, that’s exactly what it is. you don’t have to use associative arrays, regular arrays will work fine in this context too.\r\rre: the task at hand.\r\ri assume you worked it out as:\r\rstack[a] = 20;\r\ryou have to create your object first:\r\rstack = new Object();\r\rbut for your purposes i think i would use a regular array rather than an associative one. then if you name your movies mc0, mc1, mc2, mc3… or something, you can go:\r\rfor(j=0,j<30,j++){\r_ _ _ _ eval(“mc”+j)._y = stack[j];\r}\r\rand have all the _y positions updated in one fell swoop.\r