MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Manual page 32

Developing flex components and themes in flash authoring
Table of Contents

Advertisement

Add the ChangeEvent metadata keyword to the getter, and a
inside the setter. When the property's value is set, the component dispatches the
Since the getter is bound to the ChangeEvent
listen for when that property changes.
At the top of the class file, you must also add the Event metadata keyword to identify
an event that this component emits.
The following ActionScript class file shows how to bind a property to an event:
[Event("change")]
class BindChar extends mx.core.UIComponent {
static var symbolName:String="BindChar";
static var symbolOwner:Object = BindChar;
var className:String = "BindChar";
function BindChar() {
}
// This example uses a TextField to store and display the character.
var myCharField:TextField;
function init() {
super.init();
tabEnabled = true;
invalidate();
}
function keyDown(evt:Object):Void {
//Triggers the setter on every keystroke.
char = String.fromCharCode(evt.ascii);
}
[ChangeEvent("change")]
public function get char():String {
return myCharField.text;
}
public function set char(c:String) {
myCharField.text = c;
dispatchEvent({ type: "change" });
}
}
The following MXML file binds the component's
property:
text
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*" >
<BindChar id="myComp1" char="F" />
<mx:TextArea id="ta1" text="{myComp1.char}" />
</mx:Application>
32
Chapter 2: Creating Basic Components in Flash MX 2004
dispatchEvent()
, the binding subsystem knows what to
change
property to the TextArea control's
char
method call
event.
change
as
change

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX - DEVELOPING COMPONENTS AND THEMES and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents