MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual page 21

Creating advanced components
Table of Contents

Advertisement

// Draw a simple border around everything.
lineStyle(1,0x000000,100);
drawRect(0, 0, width, height);
}
/*** h) Add methods, properties, and metadata. ***/
// The general pattern for properties is to specify a private
// holder variable.
private var __labelPlacement:String = "left";
// Create a getter/setter pair so you know when it changes.
[ChangeEvent("placementChanged")]
[Inspectable(defaultValue="left", enumeration="left, right")]
function set labelPlacement(p:String) {
// Store the new value.
__labelPlacement = p;
// Add invalidateSize(), invalidateLayout(), or invalidate(), depending on
// what changed.
invalidateLayout();
dispatchEvent({type:"placementChanged"});
}
function get labelPlacement():String {
return __labelPlacement;
}
private var __text:String = "ModalText";
[ChangeEvent("textChanged")]
[Inspectable(defaultValue="ModalText")]
function set text(t:String) {
__text = t;
bTextChanged = true;
invalidate();
dispatchEvent({type:"textChanged"});
}
function get text():String {
return text_mc.text;
}
// Handle events that are dispatched by the children.
function handleEvent(evt:Object):Void {
if (evt.type == "change") {
dispatchEvent({ type: "change" });
}
// If button is clicked, toggle the editable property of the text box.
else if (evt.type = "click") {
text_mc.editable = !text_mc.editable;
}
}
}
The following is an example MXML file that instantiates the ModalText control and sets the
labelPlacement property to
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
<ModalText labelPlacement="left"/>
</mx:Application>
You may call more than one if you need to.
:
"left"
Using the ModalText example
21

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents