Main Page | Packages | Class Tree | Index | Help

xp.events

class EventHandler

Object
  |
  +--xp.events.EventHandler


class EventHandler
extends Object

The EventHandler class provides support for dynamically generating event listeners whose methods execute a simple statement involving an incoming event object and a target object You don't generally deal directly with EventHandler instances. Instead, you use the EventHandler create methods to create an object that implements a listener interface. This listener object uses an EventHandler object behind the scenes to encapsulate information about the event, the object on which to perform an action when the event occurs, the action (method) to be performed, and any argument to the method. The simplest use of EventHandler is to install a listener that calls a method on the target object with no arguments. In the following example we create a listener that invokes the toFront method on an instance of Frame myButton.addEventListener(EventHandler.create(frame, "toFront")); When myButton is pressed, the statement frame.toFront() will be executed. One could get the same effect using the Delegate class The next simplest use of EventHandler is to extract a property value from the first argument of the method in the listener interface (typically an event object) and use it to set the value of a property in the target object. In the following example we create an EventListener that sets the nextFocusableComponent property of the target object to the value of the "source" property of the event. EventHandler.create(target, "nextFocusableComponent", "source") Probably the most common use of EventHandler is to extract a property value from the source of the event object and set this value as the value of a property of the target object. In the following example we create a listener that sets the "label" property of the target object to the value of the "text" property of the source (the value of the "source" property) of the event. EventHandler.createHandler(button, "label", "source.text") The event property may be be "qualified" with an arbitrary number of property prefixes delimited with the "." character. The "qualifying" names that appear before the "." characters are taken as the names of properties that should be applied, left-most first, to the event object. For example, the following listener EventHandler.createHandler(source, "a", "b.c.d") might be written as the following inner class (assuming all the properties had canonical getter methods and returned the appropriate types): //Equivalent code using an inner class instead of EventHandler. var actionListener = { source:this, handleEvent:function(e:Event) { source.setA(e.target.getB().getC().isD()); } }



Field Summary

public
eventProperty: String
Returns the property of the event that should be used in the action applied to the target.

public
eventType: String
Returns the event type that will trigger the action.

public
property: String
Returns the name of the target's writable property that this event handler will set, or the name of the method that this event handler will invoke on the target.

public
target: Object
Returns the object on which this event handler will perform an action

Constructor

public
EventHandler ( target: Object, property: String, eventProperty: String, eventType: String)
Creates a new EventHandler object; you generally use one of the create methods instead of invoking this constructor directly

Method Summary

public static
createHandler ( target: Object, property: String, eventProperty: String, eventType: String ): Function
If target and property are set creates a listener in which all event types apply the handler's action to the target. If target,property and eventProperty are set creates a listener in which all event types pass the value of the event expression, eventProperty, to the final method in the statement, property, which is applied to the target. If all params are set creates a listener in which the event type named eventType passes the value of the event expression, eventProperty, to the final method in the statement, property, which is applied to the target.

public
handleEvent ( e: Event ): Void
Callback for events



Field Documentation

eventProperty

public var eventProperty: String
Returns the property of the event that should be used in the action applied to the target.

eventType

public var eventType: String
Returns the event type that will trigger the action.

property

public var property: String
Returns the name of the target's writable property that this event handler will set, or the name of the method that this event handler will invoke on the target.

target

public var target: Object
Returns the object on which this event handler will perform an action


Constructor Documentation

EventHandler

public function EventHandler(target: Object,
 property: String,
 eventProperty: String,
 eventType: String)
Creates a new EventHandler object; you generally use one of the create methods instead of invoking this constructor directly

Parameters:
target
- the object that will perform the action
property
- the (possibly qualified) name of a writable property or method on the target
eventProperty
- the (possibly qualified) name of a readable property of the incoming event
eventType
- the name of the event type that should trigger the action

Method Documentation

createHandler

public static function createHandler(target: Object,
 property: String,
 eventProperty: String,
 eventType: String): Function
If target and property are set creates a listener in which all event types apply the handler's action to the target. If target,property and eventProperty are set creates a listener in which all event types pass the value of the event expression, eventProperty, to the final method in the statement, property, which is applied to the target. If all params are set creates a listener in which the event type named eventType passes the value of the event expression, eventProperty, to the final method in the statement, property, which is applied to the target.

Parameters:
target
- the object that will perform the action
property
- the (possibly qualified) name of a writable property or method on the target
eventProperty
- the (possibly qualified) name of a readable property of the incoming event
eventType
- the name of the event type that should trigger the action

handleEvent

public function handleEvent(e: Event): Void
Callback for events


The documentation was generated from the following file:


Generated on 10/30/2005 9:34:02 PM by AS2Doc