Skip to main content
Known Participant
December 30, 2013
Question

How to do random shuffling of Movie Clips by maintaining Row-Column symmetry ?

  • December 30, 2013
  • 1 reply
  • 3608 views

Hi all !

This is for an alphabet learning app developed by procedural coding (not OOP). In level two the player (kids) have to click on alphabet movieclips in an orderly fashion (A, B, C, D....etc.,) eventhough they are placed in a disorderly manner (eg., C, D, Z, A etc.,)  before a count down timer hits zero. As the kid clicks on each alphabet block "in an orderly manner" the alpha changes, and the sound of the alphabet is played.

The challenging task that i cannot achieve is to randomly shuffle the MovieClip blocks in such a manner that the positions should change but the symmetry should be maintained (in contrast to shuffling in such a way that the movieclips position get haphazardly displaced). Even after shuffling the chess-board like symmetry of rows and columns should be maintained. Only the blocks should get repositioned.

Pls see the Before and After Shuffling Images Below:

Before Shuffling:

After Shuffling:

Pls kindly help

Thanks in advance

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
December 30, 2013

Your use of the word symmetry is likely confusing the explanation of what you are after.  If your goal is to maintain the grid formation while the letter positions change within that formation then you can do that using an array (containing the instance names) that you shuffle into a random order and some looping thru it for the placement.

Here are the two portions of coding that you will need to work into whatever you currently have...

Below is a function for shuffling an array using AS3.

function shuffle(a:Array) {
    var p:int;
    var t:*;
    var ivar:int;
    for (ivar = a.length-1; ivar>=0; ivar--) {
        p=Math.floor((ivar+1)*Math.random());
        t = a[ivar];
        a[ivar] = a

;
        a

= t;
    }
}

// Usage:
shuffle(letterArray);

For the placement you can do it using one or two loops.  Here is a two-loop approach....

var count:int = 0;

var rowY:Number = 0; // replace with starting y value

for(var i:int=0; i<5; i++){   // for each row

     

      var colX:Number = 0; // replace with starting x value

      for(var j:int=0; j<6; j++){  // for each column in the current row

             letterArray[count].x = colX;

             letterArray[count].y = rowY;

             colX += distanceBetweenXs;

             count += 1;  // increment for the next letter in the array

       }

      rowY += distanceBetweenYs;

}

Known Participant
December 30, 2013

Hi !

I need some help with my adobe community forum login issues. For some

reason that i have no idea about, my IP address has been banned. The only

reason that i can think of is, i have included a youtube upload link in one

of my posts. But then, the very same link was directly related to a

question that i had posted in the forum, and nothing more. I do not know if

the forum moderators took it for a spam message and banned my IP address

altogether. Kindly inform me how to resolve this issue.

Thanks

regards Arshad

Ned Murphy
Legend
December 30, 2013

Hello Ned,

is this you that i am communicating with. If so, great.

I thought it was some kind of an automated mail sent by adobe to all the

forum members once they started with a forum discussion.

I was extremely excited when i got your reply for my random shuffling

question, (and in fact 20 minutes after you posted it) and ever since i

have been trying to post a reply in the forum but since they banned my IP

address i could not Sign In to my account.

I tried the code that you sent but then only one movieclip is getting

shuffled. Each time i run the .Fla file, another movieclip gets displaced,

but its always just one movieclip. And also, every time, the movieclip that

gets displaced goes to the same position, that is, the final movieclip in

the grid.

Pls find the four attachments that i am sending along with this mail. One

of them is the code, the way i have modified it and the other three are

screenshots of the debugging sessions.

thanks a million

arshad


If you look at the posting with my code I later added a line that might solve the problem you describe.  It's the one that adjusts the count variable to advance to each item in the array.  It comes right after the line where you increment colX....

             colX += distanceBetweenXs;

             count += 1;  // increment for the next letter in the array

While you can answer postings via email, you cannot attach files that way.