Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 190

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

The following code example defines the StyledRectangle component and the
style:
package myComponents
{
// skinstyle/myComponents/StyledRectangle.as
import mx.core.UIComponent;
import mx.styles.CSSStyleDeclaration;
import mx.styles.StyleManager;
import flash.display.GradientType;
// Insert the [Style] metadata tag to define the name, type
// and other infomration about the style property for the
// MXML compiler.
[Style(name="fillColors",type="Array",format="Color",inherit="no")]
public class StyledRectangle extends UIComponent
{
// Define a static variable.
private static var classConstructed:Boolean = classConstruct();
// Define a static method.
private static function classConstruct():Boolean {
if (!StyleManager.getStyleDeclaration("StyledRectangle"))
{
// If there is no CSS definition for StyledRectangle,
// then create one and set the default value.
var newStyleDeclaration:CSSStyleDeclaration =
newStyleDeclaration.setStyle("fillColors", [0xFF0000,
0x0000FF]);
StyleManager.setStyleDeclaration("StyledRectangle",
newStyleDeclaration, true);
}
return true;
}
// Constructor
public function StyledRectangle() {
super();
}
// Define a default size of 100 x 100 pixels.
override protected function measure():void {
super.measure();
measuredWidth = measuredMinWidth = 100;
measuredHeight = measuredMinHeight = 100;
}
190
Creating Custom Style Properties
new CSSStyleDeclaration();
fillColors

Advertisement

Table of Contents
loading

Table of Contents