mx.states

# SetEventHandler - AS3 Flex

Package | mx.states
Class | public class SetEventHandler
Inheritance | SetEventHandler OverrideBase OnDemandEventDispatcher Object

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The SetEventHandler class specifies an event handler that is active only during a particular view state. For example, you might define a Button control that uses one event handler in the base view state, but uses a different event handler when you change view state.

You use this class in the `overrides` property of the State class.

MXML Syntax Show MXML Syntax
Hide MXML Syntax

The `<mx:SetEventHanlder>` tag has the following attributes:

      <mx:SetEventHandler
      Properties
      name="null"
      handlerFunction="null"
      target="null"

      Events
      handler=No default
      />

More examples

Defining a login interface by using view states
Example: Creating a simple view state
Create and apply view states
Defining view state groups
Example: Controlling layout using view states groups

Learn more

About view states
Using view state events

Related API Elements

mx.states.State
mx.states.SetProperty
mx.states.SetStyle

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | handlerFunction : Function The handler function for the event. | SetEventHandler
|  | name : String The name of the event whose handler is being set. | SetEventHandler
|  | originalHandlerFunction : Function The handler function to remove prior to applying our override. | SetEventHandler
|  | target : Object The component that dispatches the event. | SetEventHandler

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | SetEventHandler(target:EventDispatcher = null, name:String = null) Constructor. | SetEventHandler
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | OnDemandEventDispatcher
|  | apply(parent:UIComponent):void [override] Applies the override. | SetEventHandler
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | OnDemandEventDispatcher
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | OnDemandEventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | initialize():void IOverride interface method; this class implements it as an empty method. | OverrideBase
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | remove(parent:UIComponent):void [override] Removes the override. | SetEventHandler
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | OnDemandEventDispatcher
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | OnDemandEventDispatcher

Events
Click for more information on events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | handler | The event handler function to execute in response to the event that is specified by the name property. | SetEventHandler

Property Detail

### handlerFunction

property

`public var handlerFunction:Function`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The handler function for the event. This property is intended for developers who use ActionScript to create and access view states. In MXML, you can use the equivalent `handler` event attribute; do not use both in a single MXML tag.

The default value is `null.`

### name

property

`public var name:String`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The name of the event whose handler is being set. You must set this property, either in the SetEventHandler constructor or by setting the property value directly.

### originalHandlerFunction

property

`public var originalHandlerFunction:Function`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 9, AIR 1.1

The handler function to remove prior to applying our override.

The default value is `null.`

### target

property

`public var target:Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The component that dispatches the event. If the property value is `null`, Flex uses the immediate parent of the `<mx:states>` tag.

The default value is `null.`

Constructor Detail

### SetEventHandler

()
Constructor

`public function SetEventHandler(target:EventDispatcher = null, name:String = null)`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Constructor.

Parameters

| `target:EventDispatcher` (default = `null`)`` — The object that dispatches the event to be handled. By default, Flex uses the immediate parent of the State object.
| `name:String` (default = `null`)`` — The event type for which to set the handler.

Method Detail

### apply

()
method

`override public function apply(parent:UIComponent):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Applies the override. Flex retains the original value, so that it can restore the value later in the `remove()` method.

This method is called automatically when the state is entered. It should not be called directly.

Parameters

| `parent:UIComponent` — The parent of the state object containing this override. The override should use this as its target if an explicit target was not specified.

### remove

()
method

`override public function remove(parent:UIComponent):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Removes the override. The value remembered in the `apply()` method is restored.

This method is called automatically when the state is entered. It should not be called directly.

Parameters

| `parent:UIComponent` — The parent of the state object containing this override. The override should use this as its target if an explicit target was not specified.

Event Detail

### handler

Event

Event Object Type: `Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The event handler function to execute in response to the event that is specified by the `name` property.

Do not specify the `handler` property and the `handlerFunction` property in a single `<mx:SetEventHandler>` tag.

Flex does not dispatch a `handler` event. You use the `handler` key word only as an MXML attribte. When you use the `handler` handler attribute, you can specify a method that takes multiple parameters, not just the Event object; also, you can specify the handler code in-line in the MXML tag.

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00