9 Replies Latest reply on Feb 27, 2013 11:12 AM by kglad

shuffle movie clips on stage

How i add my movieclips on stage in array

when load swf onstage movieclip change their position according to array

my movieclips names are m1,m2 to m24 in 6column x4rows

var numberArray_arr:Array = new Array('0','1','2','3','4','5','6','7','8','9');

function arrayShuffle(array_arr:Array):Array{

for(var i:Number = 0; i < array_arr.length; i++){

var randomNum_num = Math.floor(Math.random() * array_arr.length)

var arrayIndex = array_arr[i];

array_arr[i] = array_arr[randomNum_num];

array_arr[randomNum_num] = arrayIndex;

}

return array_arr;

}

trace(arrayShuffle(numberArray_arr));

• 2. Re: shuffle movie clips on stage

they are on stage with their instance name m1 to m24

• 3. Re: shuffle movie clips on stage

var mcA:Array = [m1,m2,...,m24];

var positionA:Array = [];

for(var i:Number=0;i<mcA.length;i++){

postionA.push([mcA[i]._x,mcA[i]._y]);

}

shuffleF(mcA);

positionF();

function positionF():Void{

for(var i:Number=0;i<mcA.length;i++){

mcA[i]._x = positionA[i][0];

mcA[i]._y = positionA[i][1];

}

}

function shuffleF(a:Array):Array {

n = a.length;

while (n>1) {

k = Math.floor(Math.random()*n);

n--;

temp = a[n];

a[n] = a[k];

a[k] = temp;

}

return a;

}

• 4. Re: shuffle movie clips on stage

it's not working

• 5. Re: shuffle movie clips on stage

now it's working but position of movieclip out of stage

function positionF():Void{

for(var i:Number=0;i<mcA.length;i++){

mcA[i]._x =  (i%6)*Stage.width/6;

mcA[i]._y = Math.floor(i/6)*Stage.height/4;

}

}

see this image

• 6. Re: shuffle movie clips on stage

copy and paste the edited code.

• 7. Re: shuffle movie clips on stage

that code is not working

that's why i add this code

mcA[i]._x =  (i%6)*Stage.width/6;

mcA[i]._y = Math.floor(i/6)*Stage.height/4;

• 8. Re: shuffle movie clips on stage

DONE !!!!