vendredi 24 juin 2016

AS3 removing an event handler within a function

I am adding an eventListener within the first function and wish to get rid of it in the second. Removing the eventListener doesn't seem to be working and as such each subsequent call to the first function is adding more event handlers. I know one way to get around this is to not add the eventListener within the function, but doing it this way will save me a lot of work for the rest of the code. Any ideas?

function errorBoxHandler(event:Event):void
{
this.errorBox.errorOkBtn.addEventListener(MouseEvent.MOUSE_DOWN, function(event:MouseEvent){errorBoxOkHandler(event, btnSelected,listIndexNum)});
}

function errorBoxOkHandler(event:MouseEvent, btnSelected:String, listIndexNum:int):void
{   
this.errorBox.errorOkBtn.removeEventListener(MouseEvent.MOUSE_DOWN,errorBoxOkHandler);
}

Aucun commentaire:

Enregistrer un commentaire