Applying styles to custom components
145
The following ActionScript class file sets the
color
and
borderColor
styles of the
BlueButton control:
package myComponents
{
// as/myComponents/BlueButton.as
import mx.controls.Button;
public class BlueButton extends Button
{
public function BlueButton() {
super();
// Set the label text to blue.
setStyle("color", 0x0000FF);
// Set the borderColor to blue.
setStyle("borderColor", 0x0000FF);
}
}
}
The following MXML file uses the BlueButton control with the default
color
and
borderColor
styles set in your component’s class file:
<?xml version="1.0"?>
<!-- as/MainBlueButton.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComps="myComponents.*">
<MyComps:BlueButton label="Submit"/>
</mx:Application>
Setting the styles in constructor does not prevent users of the component from changing the
style. For example, the user could still set their own value for the
color
style, as the following
example shows:
<?xml version="1.0"?>
<!-- as/MainBlueButtonRed.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComps="myComponents.*">
<MyComps:BlueButton label="Submit" color="0xFF0000"/>
</mx:Application>
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...