Flash Actionscript: dynamically named array accessing

NerdUprising

[ Method ]
Joined
23 May 2003
Messages
736
was wondering if anyone could help me with this interesting problem:

in this script: (not taken out of context...rewrote to be simplified)

countCurrent = 1;
Info2 = new Array(I, need, help);
FinalVar = ["Info" + countCurrent][0];


trying to dynamically access the array from which the info will be pulled, but when this script runs... the first set of square brackets is all that is returned (FinalVar = "Info1") rather than returning "I" (the data in place 0 in the array)... It would be simple enough to simply name the array to be accessed... but this is running inside of a function that is written to repeat itself for every array (countCurrent is the number) rather than listing them all out, this allows for more arrays to be added or removed from the movie, all accessed within one function (save some time and filesize)

anyone know how (or if) I could perhaps circumlocute this, or just get it to work at all? (my apologies if you couldnt understand the crap I just wrote...lol... can give more info if needed) Much thanks
 
Isn't it better to use a multi-dimensional array (matrix) in this case? I don't know how they are represented in Flash but it might be something like this:


Info = new Array();
// Preferrably looped:
Info[0] = new Array();
...
Info[n] = new Array();

Info[0][0] = "Whatever";
 
after a little playing around... I have discovered the solution to my own problem (how nifty!)


when using any dynamically named object (variable, array, movie clip, etc) Flash needs something to throw it off course...intentionally.

when the array access operators are used, flash returns it without even thinking twice... so to get flash to read the operators as a name, there has to be "_root" before it (or _level0, if _root is being tempermental):

_root["array"+countTotal][0] (note the lack of period between root and the array access operator...)

and with this way, you can name anything heiarchially (is that a word?), so long as the last period is dropped:

_root.newMC.textMC["variable"+countTotal] = 45
 

Members online

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back