Macromedia flex 2 Manuale

Pagina di 254
Example: Creating style properties
191
        // Define the variable to hold the current gradient fill colors.
        private var fillColorsData:Array;
        private var bFillColorsChanged:Boolean = true;
        // Define variables for additional controls on the fill.
        // You can create style properties for these as well.
        private var alphas:Array = [1.0, 1.0];
        private var ratios:Array = [0x00, 0xFF];
        
        // Override styleChanged() to detect changes in your new style.
        override public function styleChanged(styleProp:String):void {
            super.styleChanged(styleProp);
            // Check to see if style changed. 
            if (styleProp=="fillColors") 
            {
                bFillColorsChanged=true; 
                invalidateDisplayList();
                return;
            }
        }
    
    
        // Override updateDisplayList() to update the component 
        // based on the style setting.
        override protected function updateDisplayList(unscaledWidth:Number,
                unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            // Check to see if style changed. 
            if (bFillColorsChanged==true) 
            {
                // Redraw gradient fill only if style changed.
                fillColorsData=getStyle("fillColors");
                graphics.beginGradientFill(GradientType.LINEAR, 
                    fillColorsData, alphas, ratios);  
                graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
            }
        }
    }
}