User Guide

Creating the ActionScript class file 149
Getter/setter methods are a straightforward way to detect changes to component properties.
Instead of declaring a regular variable with
var, declare getter/setter methods, as follows:
private var __flavorStr:String = "strawberry";
[Inspectable(defaultValue="strawberry")]
public function get flavorStr():String{
return __flavorStr;
}
public function set flavorStr(newFlavor:String) {
__flavorStr = newFlavor;
invalidate();
}
The invalidate() call causes the component to redraw itself with the new flavor. This is the
benefit of using getter/setter methods for the
flavorStr property, instead of a regular
member variable. See “Defining the draw() method” on page 165.
To define getter/setter methods, remember these points:
Precede the method name with get or set, followed by a space and the property name.
The variable that stores the propertys value cannot have the same name as the getter or
setter. By convention, precede the names of the getter and setter variables with two
underscores.
Getters and setters are commonly used in conjunction with tags to define properties that are
visible in the Property and Component inspectors.
For more information about getter/setter methods, see “About getter and setter methods” in
Learning ActionScript 2.0 in Flash.
Adding component metadata
You can add component metadata tags in your external ActionScript class files to tell the
compiler about component parameters, data binding properties, and events. Metadata tags are
used in the Flash authoring environment for a variety of purposes.
The metadata tags can only be used in external ActionScript class files. You cannot use
metadata tags in FLA files.
Metadata is associated with a class declaration or an individual data field. If the value of an
attribute is a string, you must enclose that attribute in quotation marks.
Metadata statements are bound to the next line of the ActionScript file. When defining a
component property, add the metadata tag on the line before the property declaration. The
only exception is the Event metadata tag. When defining component events, add the
metadata tag outside the class definition so that the event is bound to the entire class.