Setting default sizes
37
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
myKey
property to determine which key the user pressed.
<?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) { // backspace
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
and
_measuredPreferredHeight
properties in the
measure()
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
preferredWidth
and
preferredHeight
properties.
The following class sets the default size of the BlueButton control to 500 by 200 pixels, and uses
the
setStyle()
method to define the default
fontSize
property for the button’s label:
class BlueButton extends mx.controls.Button {
static var symbolName:String="BlueButton";
static var symbolOwner:Object = BlueButton;
var className:String = "BlueButton";
function BlueButton() {
Содержание FLEX - DEVELOPING COMPONENTS AND THEMES
Страница 1: ...Developing Flex Components and Themes in Flash Authoring ...
Страница 4: ...4 Contents ...
Страница 44: ...44 Chapter 2 Creating Basic Components in Flash MX 2004 ...
Страница 82: ...82 Index ...