function init() {
super.init();
tabEnabled = true;
invalidate();
}
function keyDown(Void):Void {
var k = Key.getCode();
trace("key: " + k);
dispatchEvent({type:"mykeydown", myKey:k});
}
}
The following MXML file handles the keyboard event that the class file emits. The MXML file
inspects the event object's
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
<mx:Script>
<![CDATA[
function handleKeyDown(evt) {
if (evt.myKey == 8) {
ta1.text = "";
} else {
ta1.text='pressed: ' + evt.myKey;
}
}
]]>
</mx:Script>
<greensquare id="myGS" mykeydown="handleKeyDown(event);" />
<mx:TextArea id="ta1" text="" />
</mx:Application>
Setting default sizes
You can set the default size of a custom component by setting the values of the
_measuredPreferredWidth
method. These values will be used if no explicit width and height are specified in the component's
MXML tag. Your measure function should not set the
properties.
The following class sets the default size of the BlueButton control to 500 by 200 pixels, and uses
the
setStyle()
class BlueButton extends mx.controls.Button {
static var symbolName:String="BlueButton";
static var symbolOwner:Object = BlueButton;
var className:String = "BlueButton";
function BlueButton() {
property to determine which key the user pressed.
myKey
// backspace
and
_measuredPreferredHeight
method to define the default
properties in the
preferredWidth
property for the button's label:
fontSize
measure()
and
preferredHeight
Setting default sizes
37
Need help?
Do you have a question about the FLEX - DEVELOPING COMPONENTS AND THEMES and is the answer not in the manual?