Package | starling.events |
Class | public class EventDispatcher |
Inheritance | EventDispatcher Object |
Subclasses | AssetManager, DelayedCall, DisplayObject, Starling, Tween |
The event mechanism is a key feature of Starling's architecture. Objects can communicate with each other through events. Compared the the Flash event system, Starling's event system was simplified. The main difference is that Starling events have no "Capture" phase. They are simply dispatched at the target and may optionally bubble up. They cannot move in the opposite direction.
As in the conventional Flash classes, display objects inherit from EventDispatcher and can thus dispatch events. Beware, though, that the Starling event classes are not compatible with Flash events: Starling display objects dispatch Starling events, which will bubble along Starling display objects - but they cannot dispatch Flash events or bubble along Flash display objects.
See also
Method | Defined By | ||
---|---|---|---|
Creates an EventDispatcher. | EventDispatcher | ||
addEventListener(type:String, listener:Function):void Registers an event listener at a certain object. | EventDispatcher | ||
dispatchEvent(event:Event):void Dispatches an event to all objects that have registered listeners for its type. | EventDispatcher | ||
dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void Dispatches an event with the given parameters to all objects that have registered
listeners for the given type. | EventDispatcher | ||
hasEventListener(type:String):Boolean Returns if there are listeners registered for a certain event type. | EventDispatcher | ||
removeEventListener(type:String, listener:Function):void Removes an event listener from the object. | EventDispatcher | ||
removeEventListeners(type:String = null):void Removes all event listeners with a certain type, or all of them if type is null. | EventDispatcher |
EventDispatcher | () | Constructor |
public function EventDispatcher()
Creates an EventDispatcher.
addEventListener | () | method |
public function addEventListener(type:String, listener:Function):void
Registers an event listener at a certain object.
Parameters
type:String | |
listener:Function |
dispatchEvent | () | method |
public function dispatchEvent(event:Event):void
Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.
Parameters
event:Event |
dispatchEventWith | () | method |
public function dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void
Dispatches an event with the given parameters to all objects that have registered listeners for the given type. The method uses an internal pool of event objects to avoid allocations.
Parameters
type:String | |
bubbles:Boolean (default = false )
| |
data:Object (default = null )
|
hasEventListener | () | method |
public function hasEventListener(type:String):Boolean
Returns if there are listeners registered for a certain event type.
Parameters
type:String |
Boolean |
removeEventListener | () | method |
public function removeEventListener(type:String, listener:Function):void
Removes an event listener from the object.
Parameters
type:String | |
listener:Function |
removeEventListeners | () | method |
public function removeEventListeners(type:String = null):void
Removes all event listeners with a certain type, or all of them if type is null. Be careful when removing all event listeners: you never know who else was listening.
Parameters
type:String (default = null )
|