My wife and I both work, we have a toddler, and neither of us are good about cleaning. Consequently after a good amount of debate my wife finally managed to convince me to get a housekeeper. Now this nice woman named Marta comes to our house every other wednesday and gets the top two floors of our house spic and span.
Ok - so how does that apply to ActionScript you ask? Well, because I know on the thursday following Marta's visit there will be two absolute truths - the house will be awesomely clean and something of mine will be missing. Whatever it is isn't really "missing", just put somewhere I wouldn't have thought to look. (Like in it's proper place!)
Like Marta does with our living room, Adobe did a major housecleaning with ActionScript 3 - so some features we're used to seeing have moved or changed in non-obvious ways. The first of which I ran across was that onReleaseOutside seems to have disappeared.
There just isn't an onReleaseOutside event anymore - so what do you do? It turns out that the answer lies in the way that events now work. GUI-related events now bubble - that is they travel up the display tree from the place where the events were first captured all the way up to the top of the tree (aka the stage).
Lets think about how that works - particularly with mouse events. If you press on a movieclip, and it doesn't capture the event, it bubbles up to that movieclips parent, and so on until it reaches the root. That means that unless an event is captured, the root (known now as the stage) will get the event. That's perfect for our needs!
So - that works, but we're not differentiating between onRelease and onReleaseOutside. Luckily for us, the MouseEvent object that our onReleaseBox function receives contains a property named target that tells us what object sent the event. All we have to do is to see if the event is coming from our box or not.
function onPressBox(evt:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_UP, onReleaseBox);
trace("press");
}
function onReleaseBox(evt:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, onReleaseBox);
trace("release");
}
box.addEventListener(MouseEvent.MOUSE_DOWN, onPressBox);
Now it's important to note that there is more than one way to skin this paricular cat. With the combination of the new event bubbling system along with a bunch of new actual events (double-click - woo hoo!) you can almost always sculpt a perfect solution for your particular problem.