Skip to main content
Known Participant
February 27, 2013
Answered

shuffle movie clips on stage

  • February 27, 2013
  • 2 replies
  • 1311 views

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

PLEASE HELP ME

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;

         array_arr = array_arr[randomNum_num];

         array_arr[randomNum_num] = arrayIndex;

      }

      return array_arr;

}

trace(arrayShuffle(numberArray_arr));

This topic has been closed for replies.
Correct answer kglad

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

function positionF():Void{

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

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

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

}

}

see this image


after i saw your message about your mc's being on-stage, i changed the code.

copy and paste the edited code.

2 replies

kglad
Community Expert
Community Expert
February 27, 2013

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

var positionA:Array = [];

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

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

}

shuffleF(mcA);

positionF();

function positionF():Void{

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

mcA._x = positionA[0];

mcA._y = positionA[1];

}

}

function shuffleF(a:Array):Array {

    n = a.length;

    while (n>1) {

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

        n--;

        temp = a;

        a = a;

        a = temp;

    }

    return a;

}

Known Participant
February 27, 2013

it's not working

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 27, 2013

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

function positionF():Void{

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

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

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

}

}

see this image


after i saw your message about your mc's being on-stage, i changed the code.

copy and paste the edited code.

Ned Murphy
Legend
February 27, 2013

How are you adding your movieclips now?

Known Participant
February 27, 2013

they are on stage with their instance name m1 to m24