MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual page 20

Creating advanced components
Table of Contents

Advertisement

[Embed(source="Modal2.swf", symbol="ModalOverSkin")]
var modeOverSkinName:String;
[Embed(source="Modal2.swf", symbol="ModalDownSkin")]
var modeDownSkinName:String;
// Note that we test for the existence of the children before creating them.
// This is optional, but we do this so a subclass can create a different
// child instead.
function createChildren():Void {
if (text_mc == undefined)
createClassObject(TextInput, "text_mc", 0, { preferredWidth: 80,
editable:false });
text_mc.addEventListener("change", this);
// Identify skin states and apply embedded assets to those states using
// the createClassObject() method:
if (mode_mc == undefined)
createClassObject(SimpleButton, "mode_mc", 1,
mode_mc.addEventListener("click", this);
}
/*** e) Implement the measure() method. ***/
// The default width is the size of the text plus the button.
// The height is dictated by the button.
function measure():Void {
_measuredPreferredWidth = text_mc.preferredWidth +
mode_mc.preferredWidth;
_measuredPreferredHeight = mode_mc.preferredHeight;
}
/*** f) Implement the layoutChildren() method. ***/
// Place the button depending on labelPlacement and fit the text in the
// remaining area.
function layoutChildren() {
text_mc.setSize(width - mode_mc.width, height);
if (labelPlacement == "left") {
mode_mc.move(width - mode_mc.width, 0);
text_mc.move(0, 0);
}
else {
mode_mc.move(0, 0);
text_mc.move(mode_mc.width, 0);
}
}
/*** g) Implement the draw() method. ***/
// Set flags when things change so we only do what we have to.
private var bTextChanged:Boolean = true;
// Set text if it changed, and draw a border.
function draw():Void {
clear();
if (bTextChanged) {
bTextChanged = false;
text_mc.text = text;
}
20
Creating Advanced Components
{ falseUpSkin: modeUpSkinName,
falseOverSkin: modeOverSkinName,
falseDownSkin: modeDownSkinName });

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents