Hi, i gather it's not possible to send arguments from Mouse Events without writing a custom EventManager. What would be a correct way to identify either the object sending the event or to pass arguments to a function specified in the Mouse Event?
Hypothetical:
I have a function which receives a MovieClip object then adds a listener to it - I want to then pass the same object onto the next function if the object receives a mouse click.
Code:
//ADD EVENT LISTENERS
public static function addFirstClickListener(myButton:MovieClip) {
myButton.addEventListener(MouseEvent.CLICK, doSomething(myButton));
}
PS: trace for "myButton" turns out correctly
button passed is [object news]
hello everyone, i'm a young starter(19) and i found this with a bit of a mix of javascript , however i don't know how to access evt.target in the function then... and don't know how to remove the listener also afterwards
hello everyone, i'm a young starter(19) and i found this with a bit of a mix of javascript , however i don't know how to access evt.target in the function then... and don't know how to remove the listener also afterwards
private function doSomething(e:MouseEvent):void{
trace(e.currentTarget); // myButton
trace(e.target); // myButton or a child of it
}
Event.currentTarget will give you the object that you attached the listener to - so for that code it would always be a reference to myButton.
Event.target will give you the object that triggered the event - so if myButton had a movieclip and a textfield inside it, you might get either object as the target depending on which _part_ of the button you clicked. It's a subtle distinction but it can save you a lot of headaches.