GODPAPER | All Packages | All Classes | Index | Frames No Frames |
NativeMappedSignal

Package | org.osflash.signals.natives
Class | public class NativeMappedSignal
Inheritance | NativeMappedSignal NativeRelaySignal Signal OnceSignal Object

The NativeMappedSignal class is used to map/transform a native Event, relayed from an IEventDispatcher, into other forms of data, which are dispatched to all listeners.

This can be used to form a border where native flash Events do not cross.

Default MXML Property `valueClasses`

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | eventClass : Class [override] The class of event permitted to be dispatched. | NativeMappedSignal
|  | eventType : String The type of event permitted to be dispatched. | NativeRelaySignal
|  | numListeners : uint [read-only] The current number of listeners for the signal. | OnceSignal
|  | target : IEventDispatcher The object considered the source of the dispatched events. | NativeRelaySignal
|  | valueClasses : Array [override] | NativeMappedSignal

Protected Properties
Hide Inherited Protected Properties
Show Inherited Protected Properties

| Property | Defined By
--- | --- | ---
|  | _eventClass : Class | NativeRelaySignal
|  | _eventType : String | NativeRelaySignal
|  | mappingFunction : Function [read-only] | NativeMappedSignal
|  | slots : SlotList | OnceSignal
|  | _target : IEventDispatcher | NativeRelaySignal
|  | _valueClasses : Array | OnceSignal

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | NativeMappedSignal(target:IEventDispatcher, eventType:String, eventClass:Class = null, ... mappedTypes) Creates a new NativeMappedSignal instance to map/transform a native Event, relayed from an IEventDispatcher, into other forms of data, which are dispatched to all listeners. | NativeMappedSignal
|  | add(listener:Function):ISlot [override] Subscribes a listener for the signal. | NativeRelaySignal
|  | addOnce(listener:Function):ISlot [override] Subscribes a one-time listener for this signal. | NativeRelaySignal
|  | addOnceWithPriority(listener:Function, priority:int = 0):ISlot Subscribes a one-time listener for this signal. | NativeRelaySignal
|  | addWithPriority(listener:Function, priority:int = 0):ISlot Subscribes a listener for the signal. | NativeRelaySignal
|  | dispatch(... valueObjects):void [override] Dispatches an object to listeners. | NativeRelaySignal
|  | dispatchEvent(event:Event):Boolean [override] | NativeMappedSignal
|  | mapTo(... objectListOrFunction):NativeMappedSignal Sets the mapping function or literal object list. | NativeMappedSignal
|  | remove(listener:Function):ISlot [override] Unsubscribes a listener from the signal. | NativeRelaySignal
|  | removeAll():void [override] Unsubscribes all listeners from the signal. | NativeRelaySignal

Protected Methods
Show Inherited Protected Methods
Show Inherited Protected Methods

| Method | Defined By
--- | --- | ---
|  | mapEvent(eventFromTarget:Event):Object For usage without extension, instances of NativeMappedSignal that are dispatching any values ( valueClasses.length > 0 ), needs to be provided with a either a mapping function or a list of object literals. | NativeMappedSignal
|  | onNativeEvent(event:Event):void [override] | NativeMappedSignal
|  | registerListener(listener:Function, once:Boolean = false):ISlot | OnceSignal
|  | registerListenerWithPriority(listener:Function, once:Boolean = false, priority:int = 0):ISlot | NativeRelaySignal
|  | registrationPossible(listener:Function, once:Boolean):Boolean | OnceSignal

Property Detail

eventClass | property

`eventClass:Class`[override]

The class of event permitted to be dispatched. Will be flash.events.Event or a subclass.

Implementation
`public function get eventClass():Class`
`public function set eventClass(value:Class):void`

mappingFunction | property |

`mappingFunction:Function` [read-only]

Implementation
`protected function get mappingFunction():Function`

valueClasses | property |

`valueClasses:Array`[override]

Implementation
`public function get valueClasses():Array`
`public function set valueClasses(value:Array):void`
Throws

| `ArgumentError` — `ArgumentError`: Invalid valueClasses argument: item at index should be a Class but was not.

Constructor Detail

NativeMappedSignal | () | Constructor

`public function NativeMappedSignal(target:IEventDispatcher, eventType:String, eventClass:Class = null, ... mappedTypes)`

Creates a new NativeMappedSignal instance to map/transform a native Event, relayed from an IEventDispatcher, into other forms of data, which are dispatched to all listeners.

Parameters

| `target:IEventDispatcher` — An object that implements the flash.events.IEventDispatcher interface.
| `eventType:String` — The event string name that would normally be passed to IEventDispatcher.addEventListener().
| `eventClass:Class` (default = `null`)`` — An optional class reference that enables an event type check in dispatch().
| `... mappedTypes` — an optional list of types that enables the checking of the types mapped from an Event.

Method Detail

dispatchEvent | () | method

`override public function dispatchEvent(event:Event):Boolean`

Parameters

| `event:Event`

Returns

| `Boolean`

mapEvent | () | method |

`protected function mapEvent(eventFromTarget:Event):Object`

For usage without extension, instances of `NativeMappedSignal` that are dispatching any values ( `valueClasses.length > 0` ), needs to be provided with a either a mapping function or a list of object literals. See `mapTo` for more info. Subclasses could override this one instead of letting the environment set the mapTo, MAKE SURE to also override `mapTo(...)` if it should not be allowed.

Parameters

| `eventFromTarget:Event`

Returns

| `Object` — An object or Array of objects mapped from an Event. The mapping of Event to data will be performed by the mapping function if it is set. A list of object literals can also be supplied in place of the mapping function. If no mapping function or object literals are supplied then an empty Array is returned or if `valueClasses.length > 0` an ArgumentError is thrown.

See also

mapTo()

mapTo | () | method |

`public function mapTo(... objectListOrFunction):NativeMappedSignal`

Sets the mapping function or literal object list. If the argument is a list of object literals then this list is dispatched to listeners.

              signal = new NativeMappedSignal(button, MouseEvent.CLICK, MouseEvent, String).mapTo("ping")
              signal.add(function(arg:String):void { trace(arg) }) // prints "ping"

And an example passing a list of literals:

              signal = new NativeMappedSignal(button, MouseEvent.CLICK, MouseEvent, String, int, Number).mapTo("ping", 3, 3.1415)
              signal.add(function(arg1:String, arg2:int, arg3:Number):void { trace(arg1, arg2, arg3) }) // prints "ping", 3, 3.1415

If the argument is a function then it is called when the event this NativeMappedSignal is listening for is dispatched. The function should return an Array or a single object. The data returned from the function is passed along as arguments in the Signal dispatch. Lets look at some examples of mapping functions and the function that is called back:

              signal = new NativeMappedSignal(button, MouseEvent.CLICK, MouseEvent, String).mapTo(function():void {
                return "ping"
              })
              signal.add(function(arg:String):void { trace(arg) }) // prints "ping"

and here's an example using a list of arguments:

              signal = new NativeMappedSignal(button, MouseEvent.CLICK, MouseEvent, String, int, Number).mapTo(function():void {
                return ["ping", 3, 3.1415]
              })
                 signal.add(function(arg1:String, arg2:int, arg3:Number):void { trace(arg1, arg2, arg3) }) // prints "ping", 3, 3.1415

You can also state your wish to receive the native Event in th mapping function by simply including an argument of type Event:

              signal = new NativeMappedSignal(button, MouseEvent.CLICK, MouseEvent, Point).mapTo(function(event:MouseEvent):void {
                return new Point(event.localX, event.localY)
              })
              signal.add(function(arg:Point):void { trace(arg) }) // prints "(x=128, y=256)"

Parameters

| `... objectListOrFunction` — This can either be a list of object literals or a function that returns list of objects.

Returns

| `NativeMappedSignal` — The NativeMappedSignal object this method was called on. This allows the Signal to be defined and mapped in one statement.

Throws

| `ArgumentError` — `ArgumentError`: Mapping function needs zero or one arguments of type Event

onNativeEvent | () | method |

`override protected function onNativeEvent(event:Event):void`

Parameters

| `event:Event`

Thu Jan 16 2014, 01:11 PM +08:00