Created
January 27, 2011 19:39
-
-
Save odoe/799072 to your computer and use it in GitHub Desktop.
Simple example of using NativeMappedSignal in a Flex Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.odoe.nmsExample.components | |
{ | |
import flash.events.MouseEvent; | |
import org.osflash.signals.natives.NativeMappedSignal; | |
import spark.components.Button; | |
import spark.components.TextInput; | |
import spark.components.supportClasses.SkinnableComponent; | |
public class MyComp extends SkinnableComponent | |
{ | |
[SkinPart(required="true")] | |
public var btn1:Button; | |
[SkinPart(required="true")] | |
public var btn2:Button; | |
[SkinPart(required="true")] | |
public var txtInput:TextInput; | |
private var btn1Clicked:NativeMappedSignal; | |
private var btn2Clicked:NativeMappedSignal; | |
protected function onButtonClicked(value:String):void | |
{ | |
txtInput.text = value; | |
} | |
override protected function partAdded(partName:String, instance:Object):void | |
{ | |
super.partAdded(partName,instance); | |
if (instance == btn1) | |
{ | |
btn1Clicked = new NativeMappedSignal(btn1, MouseEvent.CLICK, MouseEvent, String).mapTo("Button 1 was clicked"); | |
btn1Clicked.add(onButtonClicked); | |
} | |
else if (instance == btn2) | |
{ | |
btn2Clicked = new NativeMappedSignal(btn2, MouseEvent.CLICK, MouseEvent, String).mapTo("Button 2 was clicked"); | |
btn2Clicked.add(onButtonClicked); | |
} | |
} | |
override protected function partRemoved(partName:String, instance:Object):void | |
{ | |
super.partRemoved(partName,instance); | |
if (instance == btn1) | |
{ | |
btn1Clicked.removeAll(); | |
btn1Clicked = null; | |
} | |
else if (instance == btn2) | |
{ | |
btn2Clicked.removeAll(); | |
btn2Clicked = null; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment