Writing The Component's Actionscript Code; Simple Example Of A Class File; Selecting A Parent Class - MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual

Creating advanced components
Table of Contents

Advertisement

Implement the
e
Implement the
f
Implement the
g
Implement the
h
Implement the
i
Add properties, methods, styles, events, and other metadata.
j
Compile a SWC file using compc.
3
The ordering of methods that you implement in this process mirrors that in the component
instantiation life cycle. By understanding which methods are called and in what order, you can
better understand how you write a component's class file. For more information, see
component instantiation life cycle" on page
Each of the steps in this process is described in more detail in the remainder of this document.

Writing the component's ActionScript code

A component's ActionScript class extends another class, adds methods, adds getters and setters,
and defines events and event handlers for the component. When you extend an existing
component class, you can inherit from only one class. ActionScript 2.0 does not allow multiple
inheritance.
To edit ActionScript class files, you can use any text editor or an Integrated Development
Environment (IDE).

Simple example of a class file

The following is a simple example of a class file called MyComponent.as. This example contains a
minimal set of imports, methods, and declarations for a component that inherits from the
UIObject class.
//Import packages.
import mx.core.UIComponent;
class MyComponent extends UIComponent {
// Define an empty constructor.
function MyComponent() {
}
// Override the init method, and call the parent's init method.
function init():Void {
super.init();
// Call invalidate() to display graphics.
invalidate();
}
}

Selecting a parent class

Most components share some common behavior and functionality. Flex includes two base classes
to supply this commonality: UIObject and UIComponent. By extending these classes, your
components have a basic set of methods, properties, and events.
6
Creating Advanced Components
method.
createChildren()
commitProperties()
method.
measure()
method.
layoutChildren()
method.
draw()
method.
8.
"About the

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-CREATING ADVANCED COMPONENTS and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents