The sequential order of clicking movie clips fails to work in the second and further game rounds
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
