AS2 → AS3: Using onReleaseOutside
One of the things that is weird to figure out about AS3 is why a MOUSE_UP_OUTSIDE event (or something similar) was not included. This leaves for work-arounds that mimic that behavior and this is one way I've seen it done (probably not the only way, but one of the ways to skin a cat). This is the AS2 version:
-
box_mc.onPress = function():Void
-
{
-
trace("PRESSED");
-
};
-
-
box_mc.onRelease = function():Void
-
{
-
trace("RELEASED");
-
};
-
-
box_mc.onReleaseOutside = function():Void
-
{
-
trace("RELEASED OUTSIDE");
-
};
And here is the AS3 version, not as pretty, but effective:
-
box_mc.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
-
box_mc.buttonMode = true;
-
-
function handleMouseDown($evt:MouseEvent):void
-
{
-
box_mc.alpha = .5;
-
-
stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
-
}
-
-
function handleMouseUp($evt:MouseEvent):void
-
{
-
box_mc.alpha = 1;
-
-
stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
-
}
As you can see, its a bit of a hack, but it works quite well. So far I haven't had any problems using it in this manner.
If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.











No Comments
No comments yet.
Leave a comment