User Guide
136 Creating Simple Visual Components in ActionScript
// keyDown event handler.
private function myKeyDown(eventObj:KeyboardEvent):void {
// Was Ctrl key pressed?
if (eventObj.ctrlKey)
{
switch (eventObj.keyCode) {
// Was Ctrl-I pressed?
case 73 :
if (currentFontSize < maxFontSize) {
currentFontSize = currentFontSize + 1;
setStyle('fontSize', currentFontSize);
}
break;
// Was Ctrl-M pressed?
case 77 :
if (currentFontSize > minFontSize) {
currentFontSize = currentFontSize - 1;
setStyle('fontSize', currentFontSize);
}
break;
default :
break;
}
}
}
}
}
In this example, the setter updates the value of the property, and then dispatches an event to
trigger an update of any data binding destination. The name of the event is not restricted. You
can use this component in an application, as the following example shows:
<?xml version="1.0"?>
<!-- as/MainTextAreaFontControlBindingSource.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:TextAreaFontControlBinding id="myTA"
maxFontSize="{Number(myTI.text)}"/>
<mx:Label text="Enter max font size."/>
<mx:TextInput id="myTI" text="15"/>
<mx:Label text="Current max font size."/>
<mx:TextArea text="{String(myTA.maxFontSize)}"/>
</mx:Application>