Using The Modaltext Example - MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual

Creating advanced components
Table of Contents

Advertisement

Assume an initial state. Because style properties are on the object, you can set initial settings for
styles and properties so your initialization code does not have to set them when the object is
constructed, unless the user overrides the default state.
When defining the symbol, do not select the Export in First Frame option unless it is
absolutely necessary. Flash loads the component just before it is used in your Flash application,
so if you select this option, Flash preloads the component in the first frame of its parent. The
reason you typically do not preload the component in the first frame is for considerations on
the web: the component loads before your preloader begins, defeating the purpose of the
preloader.
Always implement an
the component as lightweight as possible.
Use the
invalidate()
instead of calling the

Using the ModalText example

The following code example implements the class definition for the ModalText component. The
ModalText component is a text input whose default is the noneditable mode, but you can switch
to editable mode by clicking its button.
Save the following code to the file ModalText.as, and then compile it into a SWC file using the
compc utility.
// Import all necessary classes.
import mx.core.UIComponent;
import mx.controls.SimpleButton;
import mx.controls.TextInput;
// ModalText sends a "change" event when the text of the child TextInput
control changes, a "textChanged" event when you set the text property of
ModalText, and a "placementChanged" event when you change the labelPlacement
property of ModalText.
[Event("change")]
[Event("textChanged")]
[Event("placementChanged")]
/*** a) Extend UIComponent. ***/
class ModalText extends UIComponent {n
/*** b) Implement init(). ***/
function init():Void {
super.init();
invalidate();
}
/*** c) Implement createChildren(). ***/
// Declare two children member variables.
var text_mc:TextInput;
var mode_mc:SimpleButton;
/*** d) Embed new skins used by the SimpleButton component. You can create a
SWF file that contains symbols with the names ModalUpSkin, ModalOverSkin,
and ModalDownSkin. ***/
[Embed(source="Modal2.swf", symbol="ModalUpSkin")]
var modeUpSkinName:String;
method and call the
init()
and
invalidateStyle()
method explicitly.
draw()
method, but otherwise keep
super.init()
methods to invoke the

Using the ModalText example

method
draw()
19

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents