Description

The Event class is the base class for the creation of Event objects, which are passed as parameters to event listeners when an event occurs. You can use the methods in event listener functions to modify the behavior of the event object. For example, you can make the current event listener the last one to process an event by calling the stopPropagation() or stopImmediatePropagation() method.

Syntax

new flwebgl.events.Event(type, bubbles)

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 false

Static Properties

Name Type Description
flwebgl.events.Event.ENTER_FRAME string Dispatched whenever a MovieClip enters a frame (before the timeline animation is processed)
flwebgl.events.Event.ADDED
string
Dispatched when a display element is added as a child.
flwebgl.events.Event.FRAME_CONSTRUCTED string Dispatched after the current frame is constructed (before the frame scripts are processed).
flwebgl.events.Event.EXIT_FRAME string Dispatched whenever a MovieClip exits a frame (after the timeline animation is processed).
flwebgl.events.Event.REMOVED
string
Dispatched before a display element is removed from the parent.

 

 

Methods

getBubbles()

Description

    This method indicates whether the event is bubbling or not.

Returns

  • Type - boolean

getCurrentTarget()

Description

    This method returns the object that is actively processing the Event object with an event listener.

Returns

  • Type - flwebgl.events.EventDispatcher

Example

This snippet adds an event listener to both the stage and its top most child (mc). When a child is added to 'mc', its event listner (handlerFn2) is executed. Since the ADDED event bubbles, it is sent up the hierarchy to event listeners of the stage (handlerFn1) after all the listeners of the 'mc' are executed.

function handlerFn1(e) {
    console.log("Handler 1");
    var t1 = e.getTarget();	// First child of stage
    var t2 = e.getCurrentTarget();	// Stage
}

function handlerFn2(e) {
    console.log("Handler 2");
    var t1 = e.getTarget();    // First child of stage
    var t2 = e.getCurrentTarget();// First child of stage
}

var stage = player.getStage();
var mc = player.getChildAt(0);
stage.addEventListener(flwebgl.events.Event.ADDED, handlerFn1);
mc.addEventListener(flwebgl.events.Event.ADDED, handlerFn2);

getTarget()

Description

    This method returns the event target.

Returns

  • Type - flwebgl.events.EventDispatcher

Example

See the example under getCurrentTarget().

getType()

Description

    This method indicates the event type.

Returns

  • Type - String

stopImmediatePropagation()

Description

    This method prevents processing of any event listeners in the current node and any subsequent nodes in the event flow.

Example

In this example two listeners are added for the ADDED event to the topmost child of the stage (mc). Both these execute when a child is added to 'mc'. However, from within the first event listener stopImmediatePropagation() is called and any other listeners on the 'mc' are prevented from receiving the event (eg. handlerFn2). In addition, it also prevents the event from bubbling up the hierarchy to the stage.

function handlerFn1(e) {
    e.stopImmediatePropagation(); // Stops any other listeners from receiving this event
}

function handlerFn2(e) {
    console.log("This will not execute");
}

var stage = player.getStage();
var mc = player.getChildAt(0);
mc.addEventListener(flwebgl.events.Event.ADDED, handlerFn1);
mc.addEventListener(flwebgl.events.Event.ADDED, handlerFn2);

stopPropagation()

Description

This method prevents processing of any event listeners in nodes subsequent to the current node in the event flow.

Example

In this example, a listener is added for the ADDED event to the topmost child of the stage (mc). It executes when a child is added to 'mc'. In this event listener, the event is prevented from bubbling up the hierarchy (for example, to the stage).

function handlerFn(e) {
    e.stopPropagation(); // Stops the event from bubbling up the hierarchy
}

var stage = player.getStage();
var mc = player.getChildAt(0);
mc.addEventListener(flwebgl.events.Event.ADDED, handlerFn);

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy