Example:
var btn:Sprite = new Sprite();
btn.graphics.beginFill(0x000);
btn.graphics.drawRect(-50, -50, 50, 50);
btn.graphics.endFill();
btn.x = stage.stageWidth/2;
btn.y = stage.stageHeight/2;
stage.addChild(btn);
function sampleFunction(_t:Object):void {
trace("Still working! "+_t.target);
//_t.target.removeEventListener(MouseEvent.MOUSE_DOWN, ???);
};
btn.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent){sampleFunction(e)}, false, 0, false);
Premise: I needed to pass a variable while defining the Listener for a object:
btn.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent){sampleFunction(e)}, false, 0, false);
Problem: Since I used a blank function(){} inside of the Listener, I don’t know how to later delete that function from that object (btn);
Is it possible? Or is there another way to pass variables while defining Listeners on objects?