Packageflash.events
Classpublic class Event
InheritanceEvent Inheritance Object
SubclassesActivityEvent, ContextMenuEvent, FocusEvent, HTTPStatusEvent, KeyboardEvent, MouseEvent, NetStatusEvent, ProgressEvent, StatusEvent, SyncEvent, TextEvent, TimerEvent

The Event class is used as the base class for the creation of Event objects, which are passed as parameters to event listeners when an event occurs.

The properties of the Event class carry basic information about an event, such as the event's type or whether the event's default behavior can be cancelled. For many events, such as the events represented by the Event class constants, this basic information is sufficient. Other events, however, may require more detailed information. Events associated with a mouse click, for example, need to include additional information about the location of the click event and whether any keys were pressed during the click event. Such additional information can be passed to event listeners by extending the Event class, which is what the MouseEvent class does. The Flash Player API defines several Event subclasses for common events that also require additional information. Events associated with each of the Event subclasses are described in the documentation for each class.

The methods of the Event class can be used in event listener functions to affect the behavior of the event object. Some events have an associated default behavior. For example, the doubleClick event has an associated default behavior that highlights the word under the cursor at the time of the event. Your event listener can cancel this behavior by calling the preventDefault() method. You can also make the current event listener the last one to process an event by calling the stopPropogation() or stopImmediatePropogation() methods.

View the examples.

See also
flash.events.EventDispatcher


Public Constants
 PropertyDefined by
  ACTIVATE : String = "activate"
[static] Dispatched when Flash Player gains operating system focus and becomes active.
Event
  ADDED : String = "added"
[static] Dispatched when a display object is added to the display list.
Event
  CANCEL : String = "cancel"
[static] Dispatched when a file upload or download is cancelled by the user.
Event
  CHANGE : String = "change"
[static] Dispatched after a control's value is modified.
Event
  CLOSE : String = "close"
[static] Dispatched by an Socket or XMLSocket object after a network connection is closed.
Event
  COMPLETE : String = "complete"
[static] Dispatched when data has loaded successfully.
Event
  CONNECT : String = "connect"
[static] Dispatched when a network connection has been established.
Event
  DEACTIVATE : String = "deactivate"
[static] Dispatched when Flash Player loses operating system focus and is becoming inactive.
Event
  ENTER_FRAME : String = "enterFrame"
[static] Dispatched when the playhead is entering a new frame.
Event
  ID3 : String = "id3"
[static] Dispatched by a Sound object when ID3 data is available for an MP3 sound.
Event
  INIT : String = "init"
[static] Dispatched by a LoaderInfo object when the properties and methods of a loaded SWF file are accessible.
Event
  MOUSE_LEAVE : String = "mouseLeave"
[static] Dispatched by the Stage object when the mouse pointer moves out of the Flash Player window area.
Event
  OPEN : String = "open"
[static] Dispatched by a LoaderInfo, URLLoader, URLStream or FileReference object when a network operation starts.
Event
  REMOVED : String = "removed"
[static] Dispatched when a display object is about to be removed from the display list.
Event
  RENDER : String = "render"
[static] Dispatched when the display list is about to be updated and rendered.
Event
  RESIZE : String = "resize"
[static] Dispatched when scaleMode property of the Stage object is set to StageScaleMode.NO_SCALE and the SWF file has been resized.
Event
  SCROLL : String = "scroll"
[static] Dispatched by a TextField object after the user scrolls.
Event
  SELECT : String = "select"
[static] Dispatched by a FileReference object when an item has been selected.
Event
  SOUND_COMPLETE : String = "soundComplete"
[static] Dispatched by a Sound object when a sound has finished playing.
Event
  TAB_CHILDREN_CHANGE : String = "tabChildrenChange"
[static] Dispatched by an InteractiveObject instance when the value of the object's tabChildren flag changes.
Event
  TAB_ENABLED_CHANGE : String = "tabEnabledChange"
[static] Dispatched by an InteractiveObject instance when the the object's tabEnabled flag changes.
Event
  TAB_INDEX_CHANGE : String = "tabIndexChange"
[static] Dispatched by an InteractiveObject instance when the value of the object's tabIndex property changes.
Event
  UNLOAD : String = "unload"
[static] Dispatched by a LoaderInfo object whenever a loaded object is removed using the unload() method of the Loader object, or when a second load is performed by the same Loader object and the orignal content is removed prior to the load beginning.
Event
Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties
 PropertyDefined by
  bubbles : Boolean
[read-only] Indicates whether an event is a bubbling event.
Event
  cancelable : Boolean
[read-only] Indicates whether the behavior associated with the event can be prevented.
Event
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  currentTarget : Object
[read-only] Indicates the object that is actively processing the Event object with an event listener.
Event
  eventPhase : uint
[read-only] Indicates the current phase in the event flow.
Event
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  target : Object
[read-only] Indicates the event target.
Event
  type : String
[read-only] Indicates the type of event.
Event
Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods
 FunctionDefined by
  
Event(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
Creates an Event object to pass as a parameter to event listeners.
Event
  
Duplicates an instance of an Event subclass.
Event
  
formatToString(className:String, ... arguments):String
A utility function that you use to implement the toString() method in your custom Event class.
Event
 Inherited
Indicates whether an object has a specified property defined.
Object
  
This method checks whether preventDefault() has been called on the event and returns true if preventDefault() has been called and false otherwise.
Event
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
Cancels an event's default behavior if that behavior can be cancelled.
Event
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
  
Prevents processing of any event listeners in the current node and any subsequent nodes in the event flow.
Event
  
Prevents processing of any event listeners in nodes subsequent to the current node in the event flow.
Event
  
Returns a string containing all the properties of the Event object.
Event
 Inherited
Returns the primitive value of the specified object.
Object
Constant detail
ACTIVATE constant
public static const ACTIVATE:String = "activate"

Dispatched when Flash Player gains operating system focus and becomes active.

This event has the following characteristics:

PropertiesValues
targetAny DisplayObject with a listener registered for the ACTIVATE event. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.Stage, DEACTIVATE
ADDED constant
public static const ADDED:String = "added"

Dispatched when a display object is added to the display list. The following methods trigger this event: DisplayObjectContainer.addChild(), DisplayObjectContainer.addChildAt(), DisplayObjectContainer.setChildIndex().

This event has the following characteristics:

PropertiesValues
targetThe DisplayObejct being added to the display list. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesYes.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.DisplayObjectContainer, flash.display.MovieClip, REMOVED
CANCEL constant
public static const CANCEL:String = "cancel"

Dispatched when a file upload or download is cancelled by the user.

This event has the following characteristics:

PropertiesValues
targetThe FileReference on which the upload or download has been cancelled. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.net.FileReference
CHANGE constant
public static const CHANGE:String = "change"

Dispatched after a control's value is modified. Contrast this with the textInput event, which is dispatched before the value is modified. Unlike the W3C DOM Event Model version of the change event, which dispatches the event only after the control loses focus, the ActionScript 3.0 version of the change event is dispatched any time the control changes. For example, if a user types text into a text field, a change event is dispatched after every keystroke.

This event has the following characteristics:

PropertiesValues
targetThe control who's value has been modified. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesYes.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.text.TextField, flash.events.TextEvent.TEXT_INPUT
CLOSE constant
public static const CLOSE:String = "close"

Dispatched by an Socket or XMLSocket object after a network connection is closed.

This event has the following characteristics:

PropertiesValues
targetThe Socket or XMLSocket who's connection has been closed. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.net.Socket, flash.net.XMLSocket
COMPLETE constant
public static const COMPLETE:String = "complete"

Dispatched when data has loaded successfully.

This event has the following characteristics:

PropertiesValues
targetThe network object that has completed loading. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.LoaderInfo, flash.media.Sound, flash.net.FileReference, flash.net.URLLoader, flash.net.URLStream
CONNECT constant
public static const CONNECT:String = "connect"

Dispatched when a network connection has been established.

This event has the following characteristics:

PropertiesValues
targetThe Socket or XMLSocket that has established a network connection. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.net.Socket, flash.net.XMLSocket
DEACTIVATE constant
public static const DEACTIVATE:String = "deactivate"

Dispatched when Flash Player loses operating system focus and is becoming inactive.

This event has the following characteristics:

PropertiesValues
targetAny DisplayObject with a listener registered for the DEACTIVATE event. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.Stage, ACTIVATE
ENTER_FRAME constant
public static const ENTER_FRAME:String = "enterFrame"

Dispatched when the playhead is entering a new frame. If the playhead is not moving, or if there is only one frame, display objects dispatch this event continuously in conjunction with the frame rate.

This event has the following characteristics:

PropertiesValues
targetAny DisplayObject with a listener registered for the ENTER_FRAME event. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.DisplayObject
ID3 constant
public static const ID3:String = "id3"

Dispatched by a Sound object when ID3 data is available for an MP3 sound.

This event has the following characteristics:

PropertiesValues
targetThe Sound object loading the MP3 for which ID3 data is now available. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.media.Sound
INIT constant
public static const INIT:String = "init"

Dispatched by a LoaderInfo object when the properties and methods of a loaded SWF file are accessible. A LoaderInfo object dispatches the init event when the following two conditions exist:

This event has the following characteristics:

PropertiesValues
targetThe LoaderInfo associated with the SWF being loaded. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.LoaderInfo
MOUSE_LEAVE constant
public static const MOUSE_LEAVE:String = "mouseLeave"

Dispatched by the Stage object when the mouse pointer moves out of the Flash Player window area.

This event has the following characteristics:

PropertiesValues
targetThe Stage object. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.Stage, flash.events.MouseEvent
OPEN constant
public static const OPEN:String = "open"

Dispatched by a LoaderInfo, URLLoader, URLStream or FileReference object when a network operation starts.

This event has the following characteristics:

PropertiesValues
targetThe network object that has opened a connection. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.LoaderInfo, flash.media.Sound, flash.net.FileReference, flash.net.URLLoader, flash.net.URLStream
REMOVED constant
public static const REMOVED:String = "removed"

Dispatched when a display object is about to be removed from the display list. Two methods of the DisplayObjectContainer class generate this event: removeChild() and removeChildAt().

The following methods of a DisplayObjectContainer object also generate this event if an object must be removed to make room for the new object: addChild(), addChildAt(), and setChildIndex().

This event has the following characteristics:

PropertiesValues
targetThe DisplayObejct being removed from the display list. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesYes.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.DisplayObjectContainer, flash.display.MovieClip, ADDED
RENDER constant
public static const RENDER:String = "render"

Dispatched when the display list is about to be updated and rendered. This event provides the last opportunity for objects listening for this event to make changes before the display list is rendered. Flash Player renders the display list as the default behavior. You must call the invalidate() method of the Stage object each time you want Flash Player to send a render event. Render events are dispatched to an object only if there is mutual trust between it and the object that called Stage.invalidate().

Note: This event is not dispatched if Flash Player window is not rendering. This is the case when the Flash Player window is either minimized or obscured.

This event has the following characteristics:

PropertiesValues
targetAny DisplayObject with a listener registered for the RENDER event. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. The default behavior cannot be canceled.

See also
flash.display.Stage.invalidate(), flash.display.Stage
RESIZE constant
public static const RESIZE:String = "resize"

Dispatched when scaleMode property of the Stage object is set to StageScaleMode.NO_SCALE and the SWF file has been resized.

This event has the following characteristics:

PropertiesValues
targetThe Stage object. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.Stage
SCROLL constant
public static const SCROLL:String = "scroll"

Dispatched by a TextField object after the user scrolls.

This event has the following characteristics:

PropertiesValues
targetThe TextField object that has been scrolled. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.text.TextField
SELECT constant
public static const SELECT:String = "select"

Dispatched by a FileReference object when an item has been selected.

This event has the following characteristics:

PropertiesValues
targetThe FileReference object on which an item has been selected. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.net.FileReference
SOUND_COMPLETE constant
public static const SOUND_COMPLETE:String = "soundComplete"

Dispatched by a Sound object when a sound has finished playing.

This event has the following characteristics:

PropertiesValues
targetThe Sound object on which a sound has finished playing. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.media.Sound
TAB_CHILDREN_CHANGE constant
public static const TAB_CHILDREN_CHANGE:String = "tabChildrenChange"

Dispatched by an InteractiveObject instance when the value of the object's tabChildren flag changes.

This event has the following characteristics:

PropertiesValues
targetThe InteractiveObject who's tabChildren flag has changed. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesYes.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.InteractiveObject
TAB_ENABLED_CHANGE constant
public static const TAB_ENABLED_CHANGE:String = "tabEnabledChange"

Dispatched by an InteractiveObject instance when the the object's tabEnabled flag changes.

This event has the following characteristics:

PropertiesValues
targetThe InteractiveObject who's tabEnabled flag has changed. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesYes.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.InteractiveObject
TAB_INDEX_CHANGE constant
public static const TAB_INDEX_CHANGE:String = "tabIndexChange"

Dispatched by an InteractiveObject instance when the value of the object's tabIndex property changes.

This event has the following characteristics:

PropertiesValues
targetThe InteractiveObject who's tabIndex has changed. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesYes.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.InteractiveObject
UNLOAD constant
public static const UNLOAD:String = "unload"

Dispatched by a LoaderInfo object whenever a loaded object is removed using the unload() method of the Loader object, or when a second load is performed by the same Loader object and the orignal content is removed prior to the load beginning.

This event has the following characteristics:

PropertiesValues
targetThe LoaderInfo associated with the SWF being unloaded or replaced. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.display.LoaderInfo
Property detail
bubbles property
bubbles:Boolean  [read-only]

Indicates whether an event is a bubbling event. If the event can bubble then this value is true; otherwise it is false.

When an event occurs, it moves through the three phases of the event flow: the capture phase, which flows from the top of the display list hierarchy to the node just before the target node; the target phase, which comprises the target node; and the bubbling phase, which flows from the node subsequent to the target node back up the display list hierarchy.

Some events, such as the activate and unload events, do not have a bubbling phase. The bubbles property has a value of false for events that do not have a bubbling phase.



Implementation
    public function get bubbles():Boolean
cancelable property
cancelable:Boolean  [read-only]

Indicates whether the behavior associated with the event can be prevented. If the behavior can be cancelled then this value is true; otherwise it is false.

Implementation
    public function get cancelable():Boolean

See also
Event.preventDefault()
currentTarget property
currentTarget:Object  [read-only]

Indicates the object that is actively processing the Event object with an event listener. For example, if a user clicks an OK button, the currentTarget could be the node containing that button or one of its ancestors that has registered an event listener for that event.

Implementation
    public function get currentTarget():Object
eventPhase property
eventPhase:uint  [read-only]

Indicates the current phase in the event flow. The property may contain the following numeric values:

Implementation
    public function get eventPhase():uint
target property
target:Object  [read-only]

Indicates the event target. This property contains the target node. For example, if a user clicks an OK button, the target node is the display list node containing that button.

Implementation
    public function get target():Object
type property
type:String  [read-only]

Indicates the type of event. The type is case-sensitive.

Implementation
    public function get type():String
Constructor detail
Event constructor

public function Event(type:String, bubbles:Boolean = false, cancelable:Boolean = false)

Creates an Event object to pass as a parameter to event listeners.

Parameters
type:String — The type of the event, accessible as Event.type.
bubbles:Boolean (default = false) — Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
cancelable:Boolean (default = false) — Determines whether the Event object can be cancelled. The default values is false.
Method detail
clone method

public function clone():Event

Duplicates an instance of an Event subclass. Returns a new Event object that is a copy of the original instance of the Event object. The new Event object includes all the properties of the original. When creating your own custom Event class, you must override the inherited Event.clone() method. You must provide your own implementation of clone() in order for it to duplicate the properties of your custom class.

In this example, PingEvent is a subclass of Event and therefore implements its own version of clone().

  class PingEvent extends Event {
   var URL:String;
   
  public override function clone():Event {
        return new PingEvent(type, bubbles, cancelable, URL);
     }
  }
  

Returns
Event — A new Event object that is identical to the original.
formatToString method

public function formatToString(className:String, ... arguments):String

A utility function that you use to implement the toString() method in your custom Event class. Overriding the toString() method is recommended, but not required.
  class PingEvent extends Event {
   var URL:String;
  
  public override function toString():String { 
   return formatToString("PingEvent", "type", "bubbles", "cancelable", "eventPhase", "URL"); 
     }
  }
  

Parameters
className:String — The name of your custom Event class. In the example above, the className parameter is PingEvent.
... arguments — The properties of the Event class and the properties that you add in your custom Event class. In the example above, the ...arguments parameter includes type, bubbles, cancelable, eventPhase, URL.

Returns
String — The name of your custom Event class and sting value of your ...arguments parameter.
isDefaultPrevented method

public function isDefaultPrevented():Boolean

This method checks whether preventDefault() has been called on the event and returns true if preventDefault() has been called and false otherwise.

Returns
Boolean — If preventDefault() has been called, true; otherwise false.

See also
flash.events.Event.preventDefault()
preventDefault method

public function preventDefault():void

Cancels an event's default behavior if that behavior can be cancelled. Many events have associated behaviors that Flash Player carries out by default. For example, if a user types a character into a text field, the default behavior is that the character is displayed in the text field. Because the TextEvent.TEXT_INPUT event's default behavior can be cancelled, you can use the preventDefault() method to prevent the character from appearing.

An example of a behavior that is not cancelable is the default behavior associated with the Event.REMOVED event, which is generated whenever Flash Player is about to remove a DisplayObject from the display list. The default behavior (removing the element) cannot be cancelled, so the preventDefault() method has no effect on the this default behavior.

You can use the Event.cancelable property to check whether you can prevent the default behavior associated with a particular event. If the value of Event.cancelable is true, then preventDefault() can be used to cancel the event; otherwise, preventDefault() has no effect.

See also
flash.events.Event.isDefaultPrevented(), Event.cancelable
stopImmediatePropagation method

public function stopImmediatePropagation():void

Prevents processing of any event listeners in the current node and any subsequent nodes in the event flow. This method takes effect immediately, such that it affects event listeners in the current node, unlike the stopPropagation() method, which doesn't take effect until all the event listeners in the current node are done processing.

Note: This method does not cancel the behavior associated with this event; see preventDefault for that functionality.

See also
flash.events.Event.stopPropagation()
stopPropagation method

public function stopPropagation():void

Prevents processing of any event listeners in nodes subsequent to the current node in the event flow. This method does not affect any event listeners in the current node (currentTarget), unlike the stopImmediatePropagation() method, which prevents processing of event listeners in both the current node and subsequent nodes. Additional calls to this method have no effect. This method can be called in any phase of the event flow.

Note: This method does not cancel the behavior associated with this event; see preventDefault for that functionality.

See also
flash.events.Event.stopImmediatePropagation()
toString method

public function toString():String

Returns a string containing all the properties of the Event object. The string is in the following format:

[Event type=value bubbles=value cancelable=value]

Returns
String — A string containing all the properties of the Event object.
Class examples

The following example uses the EventExample class and the Square custom class to demonstrate how to manage event bubbling.
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class EventExample extends Sprite {
        
        public function EventExample() {
            var square_0:Square = new Square(300, 0x336633);
            addChild(square_0);
            
            var square_1:Square = new Square(250, 0x669966);
            square_0.addChild(square_1);

            var square_2:Square = new Square(200, 0x66CC66);
            square_1.addChild(square_2);

            var square_3:Square = new Square(150, 0xAA0000);
            square_3.shouldBubble = false;
            square_2.addChild(square_3);

            var square_4:Square = new Square(100, 0x66FF66);
            square_3.addChild(square_4);

            var square_5:Square = new Square(50, 0xCC0000);
            square_5.shouldBubble = false;
            square_4.addChild(square_5);

            this.addEventListener(MouseEvent.CLICK, clickHandler);
        }
        
        private function clickHandler(e:Event):void {
            trace(">> stage: " + e.type + " event from " + e.target.name + " called on " + this.name);
            trace(">> --------------------------------------------");
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

class Square extends Sprite {
    private var sideLen:int;
    private var color:Number;
    public var shouldBubble:Boolean = true;

    public function Square(sideLen:int, color:Number) {
        this.sideLen = sideLen;
        this.color = color;
        init();
        draw();
    }
        
    private function init():void {
        buttonMode = true;
        this.addEventListener(MouseEvent.CLICK, firstClickHandler);
        this.addEventListener(MouseEvent.CLICK, secondClickHandler);
        this.addEventListener(MouseEvent.CLICK, thirdClickHandler);
    }
        
    private function draw():void {
        this.graphics.beginFill(color);
        this.graphics.drawRect(0, 0, sideLen, sideLen);
    }
        
    private function firstClickHandler(e:Event):void {
        trace(">> 1e: " + e.type + " event from " + e.target.name + " called on " + this.name);
        if(!shouldBubble) {
            e.stopPropagation();
        }
    }

    private function secondClickHandler(e:Event):void {
        trace(">> 2e: " + e.type + " event from " + e.target.name + " called on " + this.name);
        if(!shouldBubble) {
            e.stopImmediatePropagation();
            trace(">> --------------------------------------------");
        }
    }

    private function thirdClickHandler(e:Event):void {
        trace(">> 3e: " + e.type + " event from " + e.target.name + " called on " + this.name);
    }
}




 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/labs/flashauthoringpreview/flash/events/Event.html