User Guide
186 Creating Custom Style Properties
About overriding the styleChanged() method
When a user sets a style on a component, Flex calls the component’s styleChanged()
method, passing to it the name of the style being set. When you create a custom component,
you can override the
UIComponent.styleChanged() method to check the style name passed
to it, and handle the change accordingly, as the following example shows:
var bBackgroundColor:Boolean=false;
override public function styleChanged(styleProp:String):void {
super.styleChanged(styleProp);
// Check to see if style changed.
if (styleProp=="backgroundColor")
{
bBackgroundColor=true;
invalidateDisplayList();
return;
}
}
The styleChanged() method first calls superclass’s styleChanged() method to let the
superclass handle the style change.
After the superclass gets a call to handle the style change, your component can detect that the
user set the
backgroundColor style, and handle it. By handling the style change after the
superclass makes the change, you can override the way the superclass handles the style.
Notice that the method calls the
invalidateDisplayList() method, which causes Flex to
execute the component’s
updateDisplayList() method at the next screen update. Although
you can detect style changes in the
styleChanged() method, you still use the
updateDisplayList() method to draw the component on the screen. For more information,
see “Defining a style property” on page 189.