In some cases, you must call the
depends on where you set the skin. If you set it prior to the
call in that method takes care of it for you. But if you set skin properties late in the
invalidate()
component instantiation life cycle, you might have to call the
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
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
methods. The following example sets the color on a button instance:
setStyle()
myButton.setStyle("color", 0xFF00FF);
You cannot access style properties as ".propertyName". Instead, you must use the
methods. This abstracts the code that handles inheriting styles and updating of a
setStyle()
component after a style change.
The
getStyle()
getStyle(styleName:String);
setStyle(styleName:String, value):Void;
The
getStyle()
returns
undefined
The
setStyle()
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.
70
Chapter 3: Creating Advanced Components in Flash MX 2004
invalidate()
and
methods have the following signatures:
setStyle()
method returns a string, number, or object representing the styleName. It
if the style does not exist.
method sets a style on the object (and children if it is a cascading style).
method after changing skin properties. This
layoutChildren()
invalidate()
. If the property is inherited, it checks
undefined
method, the
method again to
or
getStyle()
or
getStyle()
Need help?
Do you have a question about the FLEX - DEVELOPING COMPONENTS AND THEMES and is the answer not in the manual?
Questions and answers