}
}
The following MXML file handles the
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*"
initialize="createListener();" >
<mx:Script>
<![CDATA[
var startAlpha:Number = 40;
var curState:Number = 100;
function myInit() {
myGS.alpha=startAlpha;
}
function modAlpha(curAlpha:Number) {
gs.alpha=curAlpha;
if (curState==100) {
curState=40;
} else {
curState=100;
}
}
]]>
</mx:Script>
<greensquare id="gs" initialize="myInit();" click="modAlpha(curState);" />
</mx:Application>
For an example of a custom component that emits and handles its events, see
compound components" on page
Handling keyboard events
Keyboard events are emitted by all components that extend the UIComponent class. To make use
of keyboard events in your MXML files, you should capture the keys and include the value of the
key in your event object, and then dispatch the keyboard event with the event object.
The following component class emits the
it. It builds an event object, adding the ASCII value of the key that the user pressed as the
property of the event object. The class extends the UIComponent class but not the UIObject
class, which does not handle this event.
[Event("mykeydown")]
class greensquare extends mx.core.UIComponent {
static var symbolName:String="greensquare";
static var symbolOwner:Object = greensquare;
var className:String = "greensquare";
function greensquare() {
}
36
Chapter 2: Creating Basic Components in Flash MX 2004
event within an
click
42.
event so that the Flex application can handle
keyDown
block:
<mx:Script>
"Creating
myKey
Need help?
Do you have a question about the FLEX - DEVELOPING COMPONENTS AND THEMES and is the answer not in the manual?
Questions and answers