In the Create New Symbol dialog box, perform the following steps:
5.
Enter BlueButton in the Name field.
a
Enter BlueButton in the Identifier field.
b
Enter BlueButton in the AS2.0 Class field.
c
To access the Identifier and AS 2.0 Class field, you must select the Export for ActionScript
check box.
Click OK.
6.
Save the FLA file as BlueButton.fla.
7.
Open a text editor and create a file called BlueButton.as. Save the ActionScript file in the same
8.
directory as the BlueButton.fla file. This should be a directory that is not in the web
application's directory structure, since these are source files for your eventual component.
Furthermore, it cannot be the same directory into which you deploy the SWC file and the
MXML file.
Add the following code to the BlueButton.as file:
9.
class BlueButton extends mx.controls.Button {
static var symbolName:String="BlueButton";
static var symbolOwner:Object = BlueButton;
var className:String = "BlueButton";
function BlueButton() {
}
function init() {
//Set the label text to blue.
setStyle("color", 0x6666CC);
super.init();
invalidate();
}
}
This script extends the mx.controls.Button class rather than the base classes (UIObject or
UIComponent). As a result, it inherits all the skins, styles, behaviors, and events of the Button
control.
It also calls the UIObject
hexadecimal equivalent of the color blue. When setting colors in
you must use the hexadecimal values for the value and surround the property name with
quotation marks.
Return to the Flash environment and enter Edit Symbols mode to edit the BlueButton symbol.
10.
Rename the existing layer main.
11.
Add the following line to the main layer's first frame:
12.
stop();
Add a new layer called assets.
13.
28
Chapter 2: Creating Basic Components in Flash MX 2004
method and sets the values of the
setStyle()
property to a
color
method calls,
setStyle()
Need help?
Do you have a question about the FLEX - DEVELOPING COMPONENTS AND THEMES and is the answer not in the manual?
Questions and answers