Yet another removeEventListner not working?
So I have an event listener that I add to a movie clip. The movie clip always exists on the root timeline, and all this code is also on the root timeline. When the user click's the movie clip I want to remove the listener so I can add a new one a few frames later. However, no matter what I do I can't get the eventListener to remove. I've even tried to add it and remove it directly after adding it, but no matter what I do I can't get it to remove...and I can still click the movie clip, and the function gets called. So a few frames later when I add the listener again and click the movie clip again, the function get's called twice instead of just once. I can't figure out what I'm missing. Any insight would be great. Here is my current code with the removeEventListener right after the add:
var tmp:String = "1st";
var question:String = "What is the question?";
answerAmc.answerAanimation.answerA.text = "To the A";
var regis:MovieClip = regis_1;
var nextquestion:String = "q2";
var mycorrect:String = "C";
var overallCorrect:int = 0;
var overallIncorrect:int = 0;
answerAmc.addEventListener(MouseEvent.CLICK, onObjectClickedHandlerA(mycorrect, "A", nextquestion, regis, tmp));
answerAmc.removeEventListener(MouseEvent.CLICK, onObjectClickedHandlerA(mycorrect, "A", nextquestion, regis, tmp));
function onObjectClickedHandlerA(thiscorrect:String, thisanswer:String, thisnextquestion:String, thisregis:MovieClip, temp:String):Function {
//this is the nested event handler to bring my variables into scope
return function(e:MouseEvent):void {
if (thiscorrect == thisanswer) {
//Play some movie clips and increment our "correct' tracking variable, then move to the next question.
Correct.gotoAndPlay(2);
Correct.gotoAndStop(2);
overallCorrect = ++overallCorrect;
trace(overallCorrect);
thisregis.gotoAndStop(1);
SoundMixer.stopAll();
gotoAndPlay(thisnextquestion);
} else {
//Play some movie clips and increment our "incorrect' tracking variable, then move to the next question.
Correct.gotoAndPlay(23);
Incorrect.gotoAndStop(2);
overallIncorrect = ++overallIncorrect;
trace(overallIncorrect);
thisregis.gotoAndStop(1);
SoundMixer.stopAll();
gotoAndPlay(thisnextquestion);
}
trace (temp);
// correct.text = color;
//trace(color);
// trace(thiscorrect);
// trace(thisanswer);
}
}
