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

Known Participant
January 1, 2014

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.


Hello Ned,

i am sorry that i cud not reply yesterday. i was on a journey. i tried changing the "count += " value but then it still fails to give the desired results. For eg., i typed

count += 6

and it showed the "output" as given below, and when i pressed "continue"  the below given swf was shown.

Output:

[SWF] ABCD%20Shuffle.swf - 15954 bytes after decompression

TypeError: Error #1010: A term is undefined and has no properties.

          at ABCDShuffle_fla::MainTimeline/frame1()[ABCDShuffle_fla.MainTimeline::frame1:37]

          at runtime::ContentPlayer/loadInitialContent()

          at runtime::ContentPlayer/playRawContent()

          at runtime::ContentPlayer/playContent()

          at runtime::AppRunner/run()

          at ADLAppEntry/run()

          at global/runtime::ADLEntry()

[UnloadSWF] ABCD%20Shuffle.swf

Test Movie terminated.

line 37 reads as follows:

letterArray[count].x = colX;

followed by line 39

letterArray[count].y = rowY;

i tried playing around by making some changes here and there, but all of them failed to give the desired results. i am sure its because "i am not doing things the right way"...

can you please point out to me where i am erring or, in which all areas i need to make changes, and how exactly

thanks a lot