Remove eventlistener for multiple movieclips of an array
Hello all
Game Scenario:
i am making a road-crossing alphabet-learning game. In the first level there are 10 alphabets say from A to J (movieclips) standing on one side of the road in a randomly shuffled manner. The player has to move the alphabets (through keyboard controls) in the alphabetical order so that it hits the entrance of a kindergarten and gets removed from the stage.
Problem Situation:
If the correct alphabet is clicked the player gets a positive score. And if the wrong alphabet is cliked, a negative score is given. This works well for the first alphabet, but, once the first alphabet hits its target and is removed from stage, it fails to work for the next alphabet since the removeEventListener code set for the case of the first alphabet continues to work for the continuing alphabets.
For eg., once the first alphabet "letA" is removed from stage, and then when i click on "letB" it gives both a positive and negative score. Positive score, since it is the next alphabet that has to be clicked. Negative score, since the "wrongClick" array contains the movieclip "letB", though it was meant for the initial situation, when "letA" was also present on stage.
Code:
var wrongClick:Array = new Array(letB, letC, letD, letE, letF, letG, letH, letI, letJ);
for (var i = 0; i<wrongClick.length ; i++){
wrongClick.addEventListener(MouseEvent.MOUSE_DOWN, negScore);
function negScore(e:MouseEvent):void{
gameScore += pointsForMiss; showGameScore();
wrongClick.removeEventListener(MouseEvent.MOUSE_DOWN, negScore);
}
}
Solution Requested:
Can someone kindly tell me how i can write the code in such a way that, once an alphabet is removed from stage, the addEventListener for the preceding array of movieclips is completely removed and a new addEventListener starts working for the rest of the alphabets that remain on stage.
thnx in advance
with best regards
shamse tabriz
