PDA

View Full Version : how can i dynamically attach movies in a loop?



chimpo
September 13th, 2003, 03:24 PM
hi, im getting a bit stuck with trying to attach movieclips according to a randomized array (for a card game)
tempx = 210;
tempy = 315;
for (i = 0; i <13; i ++)

{
trace((hand1[0][i][0]*10)+(hand1[0][i][1]));

j = new String(i);

//the element in the array give the linkage number
//i have tried to assign a variable j that increments every time
// so that can be the referenc name on stage
//have tried to assign i to be the layyer
this.attachMovie((hand1[0][i][0]*10)+(hand1[0][i][1]),j, i);
this._x = tempx;

this._y = tempy;

//so is positioned right slightly every time
tempx = tempx +10;
}

all it seems to do is writeover every card with the next one so all im left with is the last card of the hand being shown

if anyone could help i would much appreciate it!!

Voetsjoeba
September 13th, 2003, 03:32 PM
I'm placing this between AS tags - easier to read AS like that :)



tempx = 210;
tempy = 315;
for (i = 0; i <13; i ++){
trace((hand1[0][i][0]*10)+(hand1[0][i][1]));
j = new String(i);
//the element in the array give the linkage number
//i have tried to assign a variable j that increments every time
// so that can be the referenc name on stage
//have tried to assign i to be the layyer
this.attachMovie((hand1[0][i][0]*10)+(hand1[0][i][1]),j, i);
this._x = tempx;
this._y = tempy;
//so is positioned right slightly every time
tempx = tempx +10;
}

Voetsjoeba
September 13th, 2003, 03:36 PM
What do your arrays look like ?

chimpo
September 13th, 2003, 03:43 PM
thanks for replying.

the array hand1 (which is 1 of 4) was originally from a 2d array of randomized cards where each element of the first array was itself an array of 2 integers- 2 to represent the rank, 1 to represent the suit. however i sliced the orginal array into 4, ie 'shuffled' it into 4 hands, it did something weird and added an extra dimension to the array. so now to reference element [4] which would have returned you an array of 2 elements, you now have to reference [0][4]. everything is now on the 0th postion in the 1st array for some reason.

it is picking up the right elements of the array and placing them on the stage but it wiped over every one: if i do trace commands to trace the array element the 1 card lefton stage is always the last one in the array as it goes through the loop