![MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Manual Download Page 38](http://html1.mh-extra.com/html/macromedia/flex-developing-components-and-themes/flex-developing-components-and-themes_manual_3388115038.webp)
38
Chapter 2: Creating Basic Components in Flash MX 2004
}
function init() {
setStyle("fontSize", 24);
super.init();
invalidate();
}
function measure() {
_measuredPreferredWidth=500;
_measuredPreferredHeight=200;
}
}
The following MXML file instantiates the BlueButton control. All instances of this BlueButton
control have a default size of 500 by 200 pixels, with a label
fontSize
of 24.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns=”*” >
<BlueButton label="My Big Button" />
</mx:Application>
You can override custom style settings in the MXML file, as the following example shows:
<BlueButton label="My Big Button"
fontSize="12"
/>
Styling custom components
Style properties define the look of a component, from the size of the fonts used to the color of the
background. To change style properties in custom components, use the
setStyle()
method in
the component’s
init()
function. This applies the same style to all instances of the component,
but Flex application authors can override the settings of the
setStyle()
method in their MXML
tags. Any style properties that are not explicitly set in the component’s class file are inherited from
the component’s superclass.
This section includes a class file that extends an existing control. For more information on setting
up the Flash environment and exporting this custom component as a SWC file, see
“Creating the
Blue Button” on page 27
.
The following ActionScript class file sets the
color
and
themeColor
styles of the BlueButton
control:
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.