Skip to main content
Known Participant
February 24, 2008
Question

MultiDimensional array

  • February 24, 2008
  • 11 replies
  • 1328 views
I am trying to create an array that holds some info for each item in the array how would I do that?
I want to add a two variables to an array that are essentialy one item in the array. Also how would I acess them later?
a= 1;
b = 2;
myArray = [];
myArray.push [??? this is were I confused with the syntax.
I would really appreciate the help.
Thanks
This topic has been closed for replies.

11 replies

Known Participant
February 26, 2008
Oh and Im using flash mx if that makes a differance. Ive been searching the documents but have only found stuff that is to newer versions to flash.
February 26, 2008
I can't remember what part of sortOn doesn't work in Flash 6 but it does have fewer options than Flash 7 or 8. I can't remember if the Array.NUMERIC will take in Flash 6. If not, you can make your own sorting function.
February 26, 2008
I'm not really sure that sortOn will work for you in Flash 6 since everything in an array is treated as text. I am also a lousy sorter and only know how to do a bubble sort and I can only do that on keypunch cards in Fortran 4. So a quick and dirty way of sorting your multidimensional array for numerical time using the Flash sortOn would be to temporarily pad your times with leading zeroes where required, do the sort and then remove those zeroes after the sort is done. (This does assume that there are no negative times.)

There may be a better way but I'm betting that Flash can sort more efficiently than I can.

edited to say that the sortOn options added in Flash 7 was one of my favorite feature improvements.
Inspiring
February 25, 2008
Just a quick clarification for everyone reading this in the web forums, and not via a newsreader (where I presume it works fine). You cannot see the array access operator in the above posts because it is interpreted as a 'bold' formatting command for subsequent content in that post, so that's why some people's reponses omit the correction and why Dave's response above seems out of place (Dave's answer is - of course - correct, but is not apparent when viewing this thread via the web, because you cannot see what he is referring to).
If you are posting something with an array access operator example, using the variable i as the iterator, and are (for some reason) not using the attach code button for the web... then please do so with an extra space before the i, as in: [ i]. Otherwise web users will see your post go bold...and not see the array access operator. It seems easier to ask people to do that than to ask them to use j,lol.
Known Participant
February 25, 2008
nextBoom.push(tempob);
Sorry if Im just missing something obvious, but whats the differance between what I had and that?
>>What you want is:
>>nextBoom.push(tempob);
Ok so now I want to arrange the array so that the entire array is arranged by the value of time in each of the objects of the array. How would I do that?
Thanks

Inspiring
February 25, 2008
>>nextBoom.push (tempob);

That's not going to work. The push() method of arrays is just that - a
method, you don't use array access notation with it.

What you want is:

nextBoom.push(tempob);


--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/


Known Participant
February 25, 2008
Srry copied it wrong. This is what I really had for the push.
nextBoom.push (tempob);
February 25, 2008
What you say is not a true statement. It is, in fact, tracing the object proving that the object is, in fact, in the array.

What you need to do is use correct syntax to acces it. For example:

(oh and stop using keywords for variable names unless that is what you are really trying to do);

Known Participant
February 25, 2008
Srry for relying on you guys so much but Im not sure how to do this.
This is what I came up with.
nextBoom = [];
tempob = {};
tempob.time = time;
tempob.x = x;
nextBoom.push (tempob);
trace(nextBoom);
Except is not tracing anything. What am I doing wrong?
Really Appreciate the help!

Known Participant
February 25, 2008
Yeah the thing is that I have two variables
var time
var x
I want them to be associated together so that I can find the x and then find the time for that x. Then they need to be ordered from least time to most time. What method would I use to accomplish that?
February 25, 2008
create objects and add all your variables as properties of those objects and then push your objects into the array.
kglad
Community Expert
Community Expert
February 25, 2008
myArray[0] will be the first element (=1) pushed into your array, and myArray[1] will be the 2nd element (=2) pushed into your array.
kglad
Community Expert
Community Expert
February 25, 2008
:

Inspiring
February 24, 2008
PS - look up the Array class - there's a sort method you can use. With a
multidimensional array though, you'll need to use the compareFunction.

--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/


Inspiring
February 24, 2008
Push, places an item in an array, at the end of the array.

If you want to add an array to another array, you push it like any other
value:

var a = [];
var b = [1,2];
a.push(b);

trace(a[0][1]);

traces 2 - the 2nd item (index 1) in the 1st item (index 0)

You can push an object too:

var a = [];
var b = {a:1, b:2};
a.push(b);

trace(a[0].b)

traces 2 also.


HTH

--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/