User Guide

932 Chapter 7: Creating Components
Overview of a component class file
The following procedure is an overview of the creation of an ActionScript file for a component.
Some steps may be optional, depending on the type of component you create.
To write a component class file:
1.
(Optional) Import classes. (See “Importing classes” on page 933).
This allows you to refer to classes without writing out the package (for example, Button instead
of mx.controls.Button).
2.
Define the class using the class keyword; use the extend keyword to extend a parent class. (See
“Defining the class and its superclass” on page 933).
3.
Define the symbolName, symbolOwner, and className variables. (See “Identifying the class,
symbol, and owner names” on page 933).
These variables are necessary only in version 2 components.
4.
Define member variables. (See “Defining variables” on page 934).
These can be used in getter/setter methods.
5.
Define a constructor function. (See “Defining the constructor function” on page 944).
6.
Define an init() method. (See “Defining the init() method” on page 945).
This method is called when the class is created if the class extends UIComponent. If the class
extends MovieClip, call this method from the constructor function.
7.
Define a createChildren() method. (See “Defining the createChildren() method”
on page 946).
This method is called when the class is created if the class extends UIComponent. If the class
extends MovieClip, call this method from the constructor function.
8.
Define a size() method. (See “Defining the size() method” on page 947).
This method is called when the component is resized, if the class extends UIComponent. In
addition, this method is called when the components live preview is resized during authoring.
9.
Define a draw() method. (See About invalidation” on page 948).
This method is called when the component is invalidated, if the class extends UIComponent.
10.
Add a Metadata tag and declaration. (See Adding component metadata” on page 935).
Adding the tag and declaration causes getter/setter properties to appear in the Property
inspector and Component inspector in Flash.
11.
Define getter/setter methods. (See “Using getter/setter methods to define parameters
on page 935).
12.
(Optional) Create variables for every skin element/linkage used in the component. (See “About
assigning skins” on page 950).
This allows users to set a different skin element by changing a parameter in the component.