onReleaseOutside() in AS3

Some AS2 developers probably noticed quickly that our old friend, the onReleaseOutside handler, does not have an ActionScript3 counterpart. While that old handler’s uses were limited, it played an essential role in AS2 drag-and-drop implementations since a rolled-out cursor still needs to call back to the drag target to disable dragging.

Well, the onReleaseOutside event is now obsolete thanks to AS3’s new event model; so I don’t fault Adobe in the least bit for getting rid of it. However, this is yet another case of point where ratified ActionScript methodology has gone undocumented. If Adobe does have one fault with AS3, it’s that they assume these crossovers are obvious and intuitive to the average Flash tech. And that, unfortunately, has been extremely alienating to Flash’s single biggest user-base.

Anyhow, let’s get back to the issue at hand: how do we manage an onReleaseOutside event in AS3? Quite simply, we listen to the stage for ANY MOUSE_UP event. Here’s what a simple drag-and-drop script looks like in AS3:

myClip.addEventListener(MouseEvent.MOUSE_DOWN, this._onMousePress);

function _onMousePress($event:MouseEvent):void {
    stage.addEventListener(MouseEvent.MOUSE_UP, this._onMouseRelease);

function _onMouseRelease($event:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_UP, this._onMouseRelease);

1 comment so far

  1. Ely on

    Dude you just saved my life! I was trying so hard to figure the damn thing out! I’m surprised and happy to see that the solution is so simple. You’ve also opened my eyes to have the stage listen in when necessary.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: