Event handling in ActionScript 3.0

Event properties

Here is the basic rundown of common Event properties:

  • type:String
  • eventPhase:uint
  • bubbles:Boolean
  • cancelable:Boolean
  • target:Object
  • currentTarget:Object

Additional 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:

  • type: The type of event being handled. This is the same as the first parameter used to add the function as a listener in addEventListener. Ex: MouseEvent.CLICK.
  • eventPhase: The current phase of the event. This is provided as a number that relates to the constants EventPhase.CAPTURING_PHASE, EventPhase.AT_TARGET, and EventPhase.BUBBLING_PHASE, depending on which phase the listener is being called.
  • bubbles: Indicates whether or not the event is an event that bubbles (and captures). This does not mean that the event went through or is going through a capture or bubbles phase, but rather it is a kind of event that can. When clicking just the stage in the previous example, the event did not capture or bubble because stage was the only target. However, bubbles would still be true since the event was a mouse click.
  • cancelable: Indicates whether or not an event is cancelable. Cancelable events are events that, by default, can result in additional consequences that can be stopped within an event handler. An example would be typing text in a text field to add characters to that field. By default, a character is added to the field every time a key on the keyboard is pressed or some other action occurs which causes the player to change the contents of a text field. A listener listening for a text input (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.
  • target: The object which Flash targeted for the event. This is the object that would receive the event in the at target phase.
  • currentTarget: Refers to the object that is currently called by the listener when the event occurs. This is the same object on which addEventListener was called from when the listener was added.

These properties can be useful in determining specific actions that need to be taken for various events.

Example 3: Mouse up outside, ActionScript 3.0 style

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:

  1. Detect a mouse down for the desired target.
  2. In a mouse down event handler, add a listener to the stage for a mouse up.
  3. In the stage mouse up listener, check to see if the target is the original object being clicked by checking the 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.
  4. Remove the stage listener within the mouse up listener.

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).

Using Flash 9 Professional ActionScript 3.0 Preview

  1. Open Example 2.
  2. 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);

Using Flex 2

  1. Create a new Flex MXML document (or edit Example 2).
  2. Use the following MXML:


    applicationComplete="initApp()">

    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);
    }
    ]]>






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).

MovieClip vs Sprite

the following post i found on another blog I Think it's very use full for those who are new in as3.

Display Objects
One of the changes in ActionScript 3 is to be working with display objects.

  • MovieClip (flash.display.MovieClip)
  • Sprite (flash.display.Sprite) – like a MovieClip but with no frames. They are a new kind of light-weight MovieClip that doesn’t technically have any frames. Since MovieClip instances you create dynamically through ActionScript cannot have frames anyway, chances are you’d want to use a Sprite in place of a MovieClip for all dynamically created MovieClip instances.
  • Shape (flash.display.Shape) – like a Sprite but with no mouse or keyboard interactivity. They are like Sprites but they offer mouse or keyboard interactivity. In other words, these display objects cannot receive events like mouseDown or keyUp. Shape instances cannot contain any other kind of display objects nor have children of their own. You can only draw vector shapes within them using the vector drawing API‘s (beginFill, lineTo, endFill, etc). This comes as an advantage to Shapes since they use less memory and are more efficient than MovieClips and Sprites.
  • Bitmap (flash.display.Bitmap) – like a Sprite but used only for displaying bitmap images. They are much like Shapes except instead of being able to contain vector drawings; they contain bitmap images defined by a BitmapData instance. They, too, cannot contain any other display objects or children. They can interact with the mouse and keyboard.
  • Loader (flash.display.Loader) – like a Sprite but used specifically to display and contain loaded content (SWFs and images).Like Sprite, has no timeline, but is designed specifically to facilitate the loading of external display content such as external SWFs and bitmap images. When loaded, those assets displayed in the Loader instance and are accessible through the Loader’s content property.

Why, when and how should people extend the Sprite in a class vs. the MovieClip class?
It seems like they’re the same thing… but I know that a sprite is at a lower level… what benefits do you get from using sprites instead of movieclips? Or movieclips instead of sprites?

Movie clips are sprites with a timeline and methods/properties to manipulate it. Use Sprite unless you require a timeline. And if you don’t require the functionality of DisplayObjectContainer (child movie clips) and InteractiveObject (mouse events, enterFrame, etc) then you should use Shape, which is light weight and simple but Shapes do have enterFrame events ;) just not the interactive stuff - mouse or keyboard interaction :) The MovieClip class is dynamic, to make the transition to AS3 easier, whereas the Sprite class are static. You can use Sprite as a class for movieclip symbols in your timeline but you cannot navigate to any frame beyond frame 1 and you cannot have ActionScript placed on that timeline. For any of that, you would want to stick to MovieClip. And if not using any timeline features there’s no point in using MovieClip… unless you want an automatically dynamic sprite without making your own subclass ;)
Sprite is a little less memory because they don’t have to worry about frames. If u want to draw stuffs and don’t need mouse or keyboard events then its wise use shape…

www.sslcexamkerala.gov.in SSLC Examination Results 2008

get results here


SSLC Examination Results 2008


Announced on 13 May 2008

Mirror Site http://results.kerala.nic.in/sslc08/sslc08.htm

KGT Examination (Commerce Group) - SEP 2007 Results Result in PDF Format

Announced on 10 Jan 2008

SSLC (Old Scheme) Exam (SEP 2007) Result in PDF Format

Announced on 3 Jan 2008

SSLC (Old Scheme) Exam - Deaf Candidates (SEP 2007) Result in PDF Format

Announced on 3 Jan 2008

SSLC (PCN) Exam (SEP 2007) Result in PDF Format

Announced on 3 Jan 2008


PHP developer Cochin |PHP developer Kerala | PHP developer India | Flash developer/programmer Cochin | Flash developer/programmer Kerala | Flash developer/programmer India | web programmer kerala |web programmer Cochin |web programmer India |web developer kerala |Web developer Cochin | Kerala PHP | PHP freelancer| flash actionscript freelancer