Inside the
draw()
class, to draw borders, rules, and other graphical elements. You can also call the
which removes the visible objects. In general, to set lengths in the
this.layoutWidth
information on the drawing API, see the MovieClip class in Flex ActionScript Language Reference.
The following example clears the component and then draws a border around the component:
function draw():Void {
clear();
if (bTextChanged) {
bTextChanged = false;
text_mc.text = text;
}
// Draw a border around everything.
drawRect(0, 0, this.layoutWidth, this.layoutHeight);
}
Defining getters and setters
Getters and setters provide visibility to component properties and control access to those
properties by other objects.
To define getter and setter methods, precede the method name with
space and the property name. Macromedia recommends that you use initial capital letters for the
second word and each word that follows. For example:
public function get initialColorStyle(): Number
The variable that stores the property's value cannot have the same name as the getter or setter. By
convention, precede the name of the getter and setter variables with two underscores (__). In
addition, Macromedia recommends that you declare the variable as private.
The following example shows the declaration of
that get and set the value of this property:
...
private var __initialColor:Color = 42;
...
public function get initialColor():Number {
return __initialColor;
}
public function set initialColor(newColor:Number) {
__initialColor = newColor;
}
You commonly use getters and setters in conjunction with metadata keywords to define properties
that are visible, bindable, and have other properties.
Defining MXML Properties
Your custom components are usable in MXML files. For example, if you define a component in
the class called MyComponent in the ActionScript file MyComponent.as, you can reference it in
MXML as the following example shows:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
<MyComponent/>
</mx:Application>
method, you can use calls to the Flash drawing API, defined by the MovieClip
and
this.layoutHeight
draw()
properties instead of
width
, and getter and setter methods
__initialColor
Writing the component's ActionScript code
method,
clear()
method, you should use
and
. For more
height
or
, followed by a
get
set
13
Need help?
Do you have a question about the FLEX-CREATING ADVANCED COMPONENTS and is the answer not in the manual?