| wikipedia.org craigslist.org (rdu) craigslist.org (char) Diagnostica Stago |
facebook.com ncdp.org work mail sboe.state.nc.us |
addEventListener
On my stage I have a movieClip "Car" that is made up of (contains) other movieClips "Body", "Engine", and "Wheels". I want to add an Mouse_Over EventListener to Car, and I want that Listener to activate regardless of which part of the Car is moused over. However I want the resulting function to act up the entire Car, not just that part which was moused over.
Within the resulting function, if I act on event.target I'll only get part of the Car. To get the entire car I need to use event.currentTarget.
use event.currentTarget rather than event.target to select the object for which the listener is registered rather than the specific object (which could be a child) that triggered the listener
package {
//to use MovieClip it must be expressly imported
import flash.display.MovieClip;
//for listeners
import flash.events.MouseEvent;
//for color roll over
import caurina.transitions.Tweener;
import caurina.transitions.properties.ColorShortcuts;
ColorShortcuts.init();
//class must be public to be called
public class Orgchart extends MovieClip {
//constructor function
public function Orgchart() {
scavcaem.addEventListener(MouseEvent.MOUSE_OVER, onArrowOver);
scavcaem.addEventListener(MouseEvent.MOUSE_OUT, onArrowOut);
}
public function onArrowOver(event:MouseEvent):void{
//important note use event.currentTarget rather than event.target to select the object for
//which the listener is registered rather than the specific object (which could be a child)
//that triggered the listener
Tweener.addTween(event.currentTarget, {_color:0xffdd33, time:0.5, transition:"linear"});
}
public function onArrowOut(event:MouseEvent):void{
Tweener.addTween(event.currentTarget, {_color:0x000000, time:1, transition:"linear"});
}
}
}