Copy link to clipboard
Copied
Hello all.
Game Scenario:
I am making a simple "Alphabet Click" game. Alphabet movieclips are aligned in Grid form. When the player clicks on the "Start" button,
the alphabets get shuffled (grid-shuffling), and a Count Down Timer is triggered. Before the timer hits zero, the player is supposed to
click the alphabets in the correct alphabetical order. If the correct alphabet is clicked, its alpha gets changed. Once the "alpha" of
all the alphabets gets changed, the "start" button reappears, and the player should be able to play the next round (repeat the game).
Problem Situation:
The first round works fine. But, in the second round, the sequential order of clicking the alphabet-movieclips cannot be met.
Eg., the "alpha" of letterB is supposed to change, only when the player has already clicked letterA. And the "alpha" of
letterC is supposed to change only when the player has already clicked "letterA" and "letterB" in the correct order.
But, in my case, in the second round, even if the player straightaway clicks letterG, or letterR, its alpha changes.
Code:
In order to minimize the number of lines of code, i have created a smaller scenario of just nine-numbers (instead of letters)
placed in grid form.
//v1 to v9 are the instance names of other movieclips that i have created, to make the conditional statement function properly.
//ie., if movieclip n1 is clicked, then, movieclip v1 (whose alpha is already zero and hence hidden, becomes invisible. v1.visible = false;
//if(v1.visible == false){n2.addEventListener.....as shown in the code below}
var vis:Array = new Array(v1, v2, v3, v4, v5, v6, v7, v8, v9);
vis.forEach(visAttrib);
function visAttrib(v:* , index:int, array:Array){
v.alpha = 0;
}
startBtn.addEventListener(MouseEvent.CLICK, trigGame)
function trigGame(e:MouseEvent):void{
startBtn.visible = false;
//SEQUENTIAL CLICKING CODE:OPEN
this.addEventListener(Event.ENTER_FRAME, trial);
function trial(e:Event):void{
n1.addEventListener(MouseEvent.MOUSE_DOWN, alph1);
function alph1(e:MouseEvent):void
{n1.alpha = .7; v1.visible = false; n1.removeEventListener(MouseEvent.MOUSE_DOWN, alph1);}
if(v1.visible == false){n2.addEventListener(MouseEvent.MOUSE_DOWN, alph2);
function alph2(e:MouseEvent):void
{n2.alpha = .7; v2.visible = false; n2.removeEventListener(MouseEvent.MOUSE_DOWN, alph2);}
}
if(v2.visible == false){n3.addEventListener(MouseEvent.MOUSE_DOWN, alph3);
function alph3(e:MouseEvent):void
{n3.alpha = .7; v3.visible = false; n3.removeEventListener(MouseEvent.MOUSE_DOWN, alph3);}
}
//....the code continues from above in the same pattern till it reaches the code below
if(v8.visible == false){n9.addEventListener(MouseEvent.MOUSE_DOWN, alph9);
function alph9(e:MouseEvent):void
{n9.alpha = .7; v9.visible = false; n9.removeEventListener(MouseEvent.MOUSE_DOWN, alph9);
startBtn.visible = true;
var vis:Array = new Array(v1, v2, v3, v4, v5, v6, v7, v8, v9);
vis.forEach(visAttrib);
function visAttrib(v:* , index:int, array:Array){
v.visible = true;
}
var num:Array = new Array(n1, n2, n3, n4, n5, n6, n7, n8, n9);
num.forEach(numAttrib);
function numAttrib(nums:* , index:int, array:Array){nums.alpha = 1;
}
}
}
}
//SEQUENTIAL CLICKING CODE:CLOSE
}
Can anyone please try to help me out
thanks in advance
with best regards
shamse tabriz
Copy link to clipboard
Copied
what are the 'n' objects?
Copy link to clipboard
Copied
Sir,
the n objects are the movieclips..they are number-movieclips arranged in grid form...nine of them are there:
n1 to n9....they are arranged as a 3 by 3 grid so that when the player clicks the start button they get shuffled.
My actual game is based on alphabets from A to Z and an additional 4 movieclips so that it forms a total of 30 movieclips
arranged as 6 by 5 grid form.
Hope my explanation is clear
thanks again
with regards
shamse tabriz
Copy link to clipboard
Copied
then what are the v1,...,v9?
Copy link to clipboard
Copied
Your code is exceedingly hard to read, because it's nonstandard and it also is poorly indented. Let me suggest a few things:
Once you've made your code more legible, post it and let's see what we have. Here are some general suggestions you may want to think about while you're refactoring your code that may help you to just solve the problem without having to come back.
Good luck!
Copy link to clipboard
Copied
Hello kglad and Amy Balnkenship
i really appreciate your willingness to help me trobleshoot my problem....after reading both of yours replies, or response, i thought i had presented my problem-situation in a highly convoluted manner....i struggled a lot and came up with a more simple working method to my problem-situation and it seems to work well in simple situations...but when the situation gets more complicated i fails to work.
i have presented my new problem situation under a new question entitled:
if you can kindly guide me on this new situation your help will be most appreciated
with much thanks
shams
Find more inspiration, events, and resources on the new Adobe Community
Explore Now