User Guide
148 Creating Components
Defining variables
The following code sample is from Button.as file (mx.controls.Button). It defines a variable,
btnOffset, to use in the class file. It also defines the variables __label, and
__labelPlacement. The latter two variables are prefixed with a double underscore to prevent
name conflicts when they are used in getter/setter methods, and ultimately used as properties
and parameters in the component. For more information, see “Using getter/setter methods to
define parameters” on page 148 in Learning ActionScript 2.0 in Flash.
/**
* Number used to offset the label and/or icon when button is pressed.
*/
var btnOffset:Number = 0;
/**
*@private
* Text that appears in the label if no value is specified.
*/
var __label:String = "default value";
/**
*@private
* default label placement
*/
var __labelPlacement:String = "right";
Using getter/setter methods to define parameters
The simplest way to define a component parameter is to add a public member variable that
makes the parameter “inspectable.” You can do this by using the Inspectable tag in the
Component inspector, or adding the Inspectable variable as follows:
[Inspectable(defaultValue="strawberry")]
public var flavorStr:String;
However, if code that employs a component modifies the flavorStr property, the
component typically must perform an action to update itself in response to the property
change. For example, if
flavorStr is set to "cherry", the component might redraw itself
with a cherry image instead of the default strawberry image.
For regular member variables, the component is not automatically notified that the member
variable’s value has changed.