Here is the basic rundown of common Event properties:
type:StringeventPhase:uintbubbles:Booleancancelable:Booleantarget:ObjectcurrentTarget:ObjectAdditional properties will apply to subclasses. MouseEvent instances, for example, also have a relatedObject property which describes a display object related to the current event (such as the display object you rolled off of to get to the current roll over event), among others.
Some of the properties should look familiar. Here is a description of the properties listed above:
addEventListener. Ex: MouseEvent.CLICK.EventPhase.CAPTURING_PHASE, EventPhase.AT_TARGET, and EventPhase.BUBBLING_PHASE, depending on which phase the listener is being called.TextEvent.TEXT_INPUT) event can recognize when this happens and cancel this default behavior. In such a case, the cancelable property would have a value of true.These properties can be useful in determining specific actions that need to be taken for various events.
One of the shortcomings of ActionScript 3.0 events is the lack of an equivalent to the ActionScript 2.0 onReleaseOutside event. You have mouse down and mouse up events for ActionScript 3.0, but nothing dealing with the release of an event outside of a previously clicked object. Instead, you have to use a little bit of trickery using the unique behavior of the stage to determine when the mouse is clicked on an object and then released outside of it.
There are a couple of approaches to achieve this. Here's the easiest method:
target property of the event object. If so, the mouse was released over the original target. If not, the mouse was released outside of that object.Because the stage captures all mouse events you can be fairly certain that any mouse up event will be received by the stage. By adding a mouse up listener to the stage within the mouse down listener of the target object, you will know that the next time the mouse released it will be either for a mouse up over the original object clicked or outside of the object (a mouse up outside event).
Replace the timeline script in Frame 1 with the following:
function boxDown(event:MouseEvent):void {
trace("box down");
stage.addEventListener(MouseEvent.MOUSE_UP, boxUpOutside);
}
function boxUpOutside(event:MouseEvent):void {
if (event.target != box) {
trace("box up outside");
}
stage.removeEventListener(MouseEvent.MOUSE_UP, boxUpOutside);
}
box.addEventListener(MouseEvent.MOUSE_DOWN, boxDown);
Use the following MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="initApp()">
<mx:Script>
<![CDATA[
public function boxDown(event:MouseEvent):void {
trace("box down");
stage.addEventListener(MouseEvent.MOUSE_UP, boxUpOutside);
}
public function boxUpOutside(event:MouseEvent):void {
if (event.target != box) {
trace("box up outside");
}
stage.removeEventListener(MouseEvent.MOUSE_UP, boxUpOutside);
}
public function initApp():void {
box.addEventListener(MouseEvent.MOUSE_DOWN, boxDown);
}
]]>
</mx:Script>
<mx:Canvas id="box" width="200" height="200" backgroundColor="#800000">
</mx:Canvas>
</mx:Application>
Test the movie and click on the box. Try clicking and releasing the mouse while it remains over the box. Then try clicking and dragging the mouse, releasing the mouse button while the cursor is outside the box. You should see an output of just "box down" when clicking on the box and an output of both "box down" and "box up outside" when clicking on the box and releasing off of the box, even if you release the mouse outside of the Flash Player window (this is specific to mouse up events associated with the stage).