ActionScript Mouse Event Handler
Tired of your child clips not receiving mouse events because their parents eat them? Try the UberMouseListener. 2005-04-27
In flash, if you do something like:
parent.onRelease = function(){
trace("I'm the parent, do what you're told!!");
}
child.onRelease = function(){
trace("But mom, I have to go to the bathroom!");
}
The child will never say anything. But the child has to go to the bathroom. How is the parent to know?
Here's a couple AS2.0 classes that will make parents more open to what their children will say. Child clips can be added to a special listener that will allow them to recieve onMouseUp,onMouseDown,onRelease,and onPress even though their parents may eat their events. Either the topmost child can receive the event or all children under the mouse.
import tv.ubergeek.util.UberMouseListener;
var listener:UberMouseListener = UberMouseListener.getInstance();
//listener.setMode(UberMouseListener.TOPMOST); // the default, just gets the topmost clip
//listener.setMode(UberMouseListener.ALL); //sends events to all clips underneath.
listener.addClip(parent.child);
listener.addClip(parent.child.grandchild);
listener.addClip(parent.child.grandchild2);
Download UberMouseListener and Example FLA
Known Bugs:
There is no way to determine whether graphics and shapes in a movieclip are above or below a movie clip. Therefore if a clip has a child overlapping the graphics and shapes, that child will receive the event, regardless of what's on top. This is illustrated by the orange box in the example.
|