PDA

View Full Version : [AS 2.0] Problems with arrays



Snake Steel
January 9th, 2005, 10:28 AM
I'm trying to store the initial X position of five movieClips in an Array by looping through it. Should be no worries, but I only end up with "Undefined" when I trace the array afterwards...


// how many menu items
var numMenuItems:Number = 5;

// create two arrays which will hold information
var navStatus:Array = new Array(numMenuItems);
var ballX:Array = new Array(numMenuItems);

// put data in arrays
for(var i:Number = 0; i < numMenuItems; i++){
navStatus[i] = "closed";

var clip = ((i+1)+"_mc");
ballX[i] = this.ball[clip]._x;
}
// check array
trace(ballX);

Ok, it's the last bit I'm having trouble with. I want to read the X coordinate of the five ball movieClips (ball1_mc, ball2_mc...ball5_mc), and store that number in the BallX array. So I need to get the loop to work so I don't have to type this in manually...

...any help at all would be great.

thansk guys :)

glkngs
January 9th, 2005, 11:07 AM
Hey..
ballX[i] = this.ball[clip]._x; needs to be changed to:
ballX[i] = this["ball"+(i+1)+"_mc"]._x;
then it should work.

And then you dont have to make the "clip" variable.

Snake Steel
January 9th, 2005, 11:13 AM
Hey..
ballX[i] = this.ball[clip]._x; needs to be changed to:
ballX[i] = this["ball"+(i+1)+"_mc"]._x;
then it should work.

And then you dont have to make the "clip" variable.


And indeed it did! Thanks a million, mate. It really helped me out here. C:-)