![MACROMEDIA FLEX - DEVELOPING COMPONENTS AND THEMES Manual Download Page 70](http://html1.mh-extra.com/html/macromedia/flex-developing-components-and-themes/flex-developing-components-and-themes_manual_3388115070.webp)
70
Chapter 3: Creating Advanced Components in Flash MX 2004
In some cases, you must call the
invalidate()
method after changing skin properties. This
depends on where you set the skin. If you set it prior to the
layoutChildren()
method, the
invalidate()
call in that method takes care of it for you. But if you set skin properties late in the
component instantiation life cycle, you might have to call the
invalidate()
method again to
have Flash draw the new skins.
Adding styles
Adding styles is the process of registering all the graphic elements in your component with a class
and letting that class control the graphics at runtime. Flex gathers style information from style
sheets and external files, and builds a styleDeclaration object that stores this information.
When the component checks a style property, it queries its own style properties (and therefore the
properties of its ancestors). If it cannot find the style property, it checks to see if it has a
styleDeclaration object assigned to it.
If it does, it returns the corresponding property in the styleDeclaration object. If not, and the
property is not inherited, the value of the style is
undefined
. If the property is inherited, it checks
the style property of its parent component. The parent component returns the property if it has it
or checks
its
parent. When the last parent is queried and no style has been found, Flex checks for
a global style object.
To set or get styles on an instance of an object, you access the UIObject
getStyle()
or
setStyle()
methods. The following example sets the color on a button instance:
myButton.setStyle("color", 0xFF00FF);
You cannot access style properties as ".
propertyName
". Instead, you must use the
getStyle()
or
setStyle()
methods. This abstracts the code that handles inheriting styles and updating of a
component after a style change.
The
getStyle()
and
setStyle()
methods have the following signatures:
getStyle(
styleName
:String);
setStyle(
styleName
:String, value):Void;
The
getStyle()
method returns a string, number, or object representing the
styleName
. It
returns
undefined
if the style does not exist.
The
setStyle()
method sets a style on the object (and children if it is a cascading style).
You do not need to implement code in your component to support styles and style inheritance,
because it is implemented in the base classes. For more information about styles, see
Developing
Flex Applications
.