Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Since you were able to reply with the message I do not understand what your problem is with continuing the discussion you started.
If you need help with a matter involving using the forums you need to post in the forum dedicated to that purpose... http://forums.adobe.com/community/general/forum_comments
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Without seeing what you have done I am unable to determine where you are erring. I can say that using count += 6 is wrong... you want to advance thru the array one item at a time.
As far as line 37 goes, you should learn to use the trace command to help you see what is being processed. The error is indicating something you are targeting does not exist. SO use the trace command to see what part of that is failing... on the line before it use...
trace("line 37 check: ", letterArray[count], count);
Chances are one of the two values will not be what you should expect.
Copy link to clipboard
Copied
Ned, i am placing my complete code, and the output that is shown from the trace command.
Ned, is there any way that i can mail you my .Fla file
code:
//(CHANGES THAT I HAVE MADE: I HAVE ADDED THE INSTANCE NAMES OF MOVIECLIPS TO
//THE ARRAY CALLED letterArray)
var letterArray:Array = [aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz,aaa,bbb,ccc,ddd];
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;
//(CHANGES THAT I HAVE MADE: I HAVE ADDED "40" & "50" AS THE STARTING Y & X VALUES)
var rowY:Number = 40; // replace with starting y value
for(var i:int=0; i<5; i++){ // for each row
var colX:Number = 50; // replace with starting x value
for(var j:int=0; j<6; j++){ // for each column in the current row
trace("line 37 check: ", letterArray[count], count);
letterArray[count].x = colX;
letterArray[count].y = rowY;
//(CHANGES THAT I HAVE MADE: I HAVE ADDED "90" AND "70" AS THE X & Y DISTANCE)
colX += 90;
count += [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29];
}
rowY += 70;
}
//THIS IS THE OUTPUT:
[SWF] ABCD%20Shuffle.swf - 16059 bytes after decompression
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
line 37 check: [object MovieClip] 0
THE SWF FILE:
Thanks a lot
Copy link to clipboard
Copied
You should be able to see from the trace that the count variable is not changing. So that is what you need to track down. I do not know why you changed that line to what you did. What I showed in my response #5 is what you should use for incrementing the count variable .
Find more inspiration, events, and resources on the new Adobe Community
Explore Now