Remove Multiple Event Listeners.
Hello,
In some cases it is important to remove multiple event listeners in order to reduce CPU time.
Below the code btn.removeEventListener(event.type, arguments.callee); at //x does not seem to work.
var btn:Array = [mc1,mc2];
main.addEventListener(MouseEvent.CLICK, Click);
mc1.addEventListener(MouseEvent.CLICK, one);
mc2.addEventListener(MouseEvent.CLICK, two);
function Click(event:MouseEvent):void
{
for (var i:uint = 0; i<btn.length; i++)
{
//event.currentTarget.removeEventListener(event.type, arguments.callee);
//x btn.removeEventListener(event.type, arguments.callee);
trace(btn); // [object MovieClip] two times, notably mc1 and mc2 respectively.
}
}
function one(event:MouseEvent):void
{
trace(event.currentTarget + " mc1 " + event.type); // [object MovieClip] mc1 click.
}
function two(event:MouseEvent):void
{
trace(event.currentTarget + " mc2 " + event.type); // [object MovieClip], mc2 click.
}
Note that if we put the code event.currentTarget.removeEventListener(event.type, arguments.callee); inside function Click, it removes the listener fine.
The problem might be with the array but the trace in the for loop returns [object MovieClip] two times.