Packageorg.osflash.signals.natives
Classpublic class NativeMappedSignal
InheritanceNativeMappedSignal Inheritance NativeRelaySignal Inheritance Signal Inheritance OnceSignal Inheritance 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 PropertyvalueClasses



Public Properties
 PropertyDefined By
  eventClass : Class
[override] The class of event permitted to be dispatched.
NativeMappedSignal
 InheritedeventType : String
The type of event permitted to be dispatched.
NativeRelaySignal
 InheritednumListeners : uint
[read-only] The current number of listeners for the signal.
OnceSignal
 Inheritedtarget : IEventDispatcher
The object considered the source of the dispatched events.
NativeRelaySignal
  valueClasses : Array
[override]
NativeMappedSignal
Protected Properties
 PropertyDefined By
 Inherited_eventClass : Class
NativeRelaySignal
 Inherited_eventType : String
NativeRelaySignal
  mappingFunction : Function
[read-only]
NativeMappedSignal
 Inheritedslots : SlotList
OnceSignal
 Inherited_target : IEventDispatcher
NativeRelaySignal
 Inherited_valueClasses : Array
OnceSignal
Public Methods
 MethodDefined 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
 Inherited
add(listener:Function):ISlot
[override] Subscribes a listener for the signal.
NativeRelaySignal
 Inherited
addOnce(listener:Function):ISlot
[override] Subscribes a one-time listener for this signal.
NativeRelaySignal
 Inherited
addOnceWithPriority(listener:Function, priority:int = 0):ISlot
Subscribes a one-time listener for this signal.
NativeRelaySignal
 Inherited
addWithPriority(listener:Function, priority:int = 0):ISlot
Subscribes a listener for the signal.
NativeRelaySignal
 Inherited
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
 Inherited
remove(listener:Function):ISlot
[override] Unsubscribes a listener from the signal.
NativeRelaySignal
 Inherited
removeAll():void
[override] Unsubscribes all listeners from the signal.
NativeRelaySignal
Protected Methods
 MethodDefined 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
 Inherited
registerListener(listener:Function, once:Boolean = false):ISlot
OnceSignal
 Inherited
registerListenerWithPriority(listener:Function, once:Boolean = false, priority:int = 0):ISlot
NativeRelaySignal
 Inherited
registrationPossible(listener:Function, once:Boolean):Boolean
OnceSignal
Property Detail
eventClassproperty
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
mappingFunctionproperty 
mappingFunction:Function  [read-only]


Implementation
    protected function get mappingFunction():Function
valueClassesproperty 
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()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