new Event(type, bubbles, cancelable)
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.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | The type of the event. |
bubbles |
boolean | Determines whether the Event object participates in the bubbling stage of the event flow. The default value is |
cancelable |
boolean | Determines whether the Event object can be canceled. The default values is |
Example
var click = function( event )
{
trace( "click: " + event ) ;
};
var dispatcher = new EventDispatcher() ;
dispatcher.addEventListener( Event.CLICK , click ) ;
dispatcher.dispatchEvent( new Event( Event.CLICK ) ) ;
Members
-
<static, constant> ACTIVATE
-
The
ACTIVATEconstant defines the value of thetypeproperty of anactivateevent object. -
<static, constant> ADDED
-
The
Event.ADDEDconstant defines the value of thetypeproperty of anaddedevent object. -
<static, constant> ADDED_TO_STAGE
-
The
Event.ADDED_TO_STAGEconstant defines the value of thetypeproperty of anaddedToStageevent object. -
<static, constant> CANCEL
-
The
Event.CANCELconstant defines the value of thetypeproperty of acancelevent object. -
<static, constant> CHANGE
-
The
Event.CHANGEconstant defines the value of thetypeproperty of achangeevent object. -
<static, constant> CLEAR
-
The
Event.CLEARconstant defines the value of thetypeproperty of aclearevent object. -
<static, constant> CLICK
-
The
Event.CLICKconstant defines the value of thetypeproperty of aclickevent object. -
<static, constant> CLOSE
-
The
Event.CLOSEconstant defines the value of thetypeproperty of acloseevent object. -
<static, constant> COMPLETE
-
The
Event.COMPLETEconstant defines the value of thetypeproperty of acompleteevent object. -
<static, constant> CONNECT
-
The
Event.CONNECTconstant defines the value of thetypeproperty of aconnectevent object. -
<static, constant> COPY
-
The
Event.COPYconstant defines the value of thetypeproperty of acopyevent object. -
<static, constant> CUT
-
The
Event.CUTconstant defines the value of thetypeproperty of acutevent object. -
<static, constant> DEACTIVATE
-
The
Event.DEACTIVATEconstant defines the value of thetypeproperty of adeactivateevent object. -
<static, constant> FULLSCREEN
-
The
Event.FULLSCREENconstant defines the value of thetypeproperty of afullScreenevent object. -
<static, constant> INIT
-
The
Event.INITconstant defines the value of thetypeproperty of aninitevent object. -
<static, constant> OPEN
-
The
Event.OPENconstant defines the value of thetypeproperty of anopenevent object. -
<static, constant> PASTE
-
The
Event.PASTEconstant defines the value of thetypeproperty of apasteevent object. -
<static, constant> REMOVED
-
The
Event.REMOVEDconstant defines the value of thetypeproperty of aremovedevent object. -
<static, constant> REMOVED_FROM_STAGE
-
The
Event.REMOVED_FROM_STAGEconstant defines the value of thetypeproperty of aremovedFromStageevent object. -
<static, constant> RENDER
-
The
Event.RENDERconstant defines the value of thetypeproperty of arenderevent object. -
<static, constant> RESIZE
-
The
Event.RESIZEconstant defines the value of thetypeproperty of aresizeevent object. -
<static, constant> SCROLL
-
The
Event.SCROLLconstant defines the value of thetypeproperty of ascrollevent object. -
<static, constant> SELECT
-
The
Event.SELECTconstant defines the value of thetypeproperty of aselectevent object. -
<static, constant> UNLOAD
-
The
Event.UNLOADconstant defines the value of thetypeproperty of aunloadevent object. -
bubbles :boolean
-
Indicates whether an event is a bubbling event. If the event can bubble, this value is
true; otherwise it isfalse.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
activateandunloadevents, do not have a bubbling phase. Thebubblesproperty has a value offalsefor events that do not have a bubbling phase.Type:
- boolean
-
cancelable :boolean
-
Indicates whether the behavior associated with the event can be prevented. If the behavior can be canceled, this value is
true; otherwise it isfalse.Type:
- boolean
- See:
-
- system.events.Event.preventDefault()
-
currentTarget :Object
-
The object that is actively processing the Event object with an event listener. For example, if a user clicks an OK button, the current target could be the node containing that button or one of its ancestors that has registered an event listener for that event.
Type:
- Object
-
eventPhase :number
-
The current phase in the event flow. This property can contain the following numeric values:
- The capture phase (
EventPhase.NONE === 0). - The capture phase (
EventPhase.CAPTURING_PHASE === 1). - The target phase (
EventPhase.AT_TARGET === 2). - The bubbling phase (
EventPhase.BUBBLING_PHASE === 3).
Type:
- number
- The capture phase (
-
<constant> target :number
-
The timestamp at which this event was created.
A numeric value corresponding to the time for the specified date according to universal time.
Type:
- number
Example
var event = new Event( Event.CLICK ) ; trace( event.timestamp ) ;
-
target :Object
-
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.
Type:
- Object
-
type :string
-
The type of event. The type is case-sensitive.
Type:
- string
Methods
-
clone()
-
Duplicates an instance of an Event subclass.
Returns a new
Eventobject that is a copy of the original instance of the Event object. You do not normally callclone(); the EventDispatcher class calls it automatically when you redispatch an event—that is, when you calldispatchEvent(event)from a handler that is handlingevent.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 in order for it to duplicate the properties of your custom class. If you do not set all the properties that you add in your event subclass, those properties will not have the correct values when listeners handle the redispatched event.In this example,
PingEventis a subclass ofEventand therefore implements its own version ofclone().Returns:
A new Event object that is identical to the original.
Example
class UrlEvent extends Event { constructor( type , url , bubbles = false, cancelable = false ) { super( type , bubbles , cancelable ) ; this.url = url; } clone() { return new UrlEvent( this.type , this.url, this.bubbles, this.cancelable ); } toString() { return this.formatToString( this.constructor.name , "type", "url" , "bubbles", "cancelable", "eventPhase" ); } } -
formatToString(className [, rest])
-
A utility function for implementing the
toString()method in custom ActionScript 3.0 Event classes. Overriding thetoString()method is recommended, but not required.Parameters:
Name Type Argument Description classNamestring The class name to passed-in the string expression.
reststring <optional>
<repeatable>
rest The properties of the
Eventclass and the properties that you add in your customEventclass.Example
class UrlEvent extends Event { constructor( type , url , bubbles = false, cancelable = false ) { super( type , bubbles , cancelable ) ; this.url = url; } toString() { return this.formatToString( this.constructor.name , "type", "url" , "bubbles", "cancelable", "eventPhase" ); } } -
isDefaultPrevented()
-
Checks whether the
preventDefault()method has been called on the event. If thepreventDefault()method has been called, returnstrue; otherwise, returnsfalse.- See:
-
- system.events.Event.preventDefault
Returns:
If
preventDefault()has been called, returnstrue; otherwise, returnsfalse. -
isImmediatePropagationStopped()
-
Check if event.stopImmediatePropagation() was called.
-
isPropagationStopped()
-
Check if event.stopPropagation() was called.
-
preventDefault()
-
Cancels an event's default behavior if that behavior can be canceled.
Many events have associated behaviors that are carried 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_INPUTevent's default behavior can be canceled, you can use thepreventDefault()method to prevent the character from appearing.An example of a behavior that is not cancelable is the default behavior associated with the
Event.REMOVEDevent, which is generated whenever Flash Player is about to remove a display object from the display list. The default behavior (removing the element) cannot be canceled, so thepreventDefault()method has no effect on this default behavior.You can use the
Event.cancelableproperty to check whether you can prevent the default behavior associated with a particular event. If the value ofEvent.cancelableistrue, thenpreventDefault()can be used to cancel the event; otherwise,preventDefault()has no effect.- See:
-
- system.events.Event.isDefaultPrevented
- system.events.Event.cancelable
-
stopImmediatePropagation()
-
Prevents processing of any event listeners in the current node and any subsequent nodes in the event flow. This method takes effect immediately, and it affects event listeners in the current node. In contrast, the
stopPropagation()method doesn't take effect until all the event listeners in the current node finish processing.Note: This method does not cancel the behavior associated with this event; see
preventDefault()for that functionality.- See:
-
- system.events.Event.stopPropagation
- system.events.Event.preventDefault
-
stopPropagation()
-
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). In contrast, thestopImmediatePropagation()method 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:
-
- system.events.Event.stopImmediatePropagation
- system.events.Event.preventDefault
-
toString()
-
Returns the string representation of this instance.
Returns:
the string representation of this instance.