Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 192

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

Advertisement

Setting default style values
One of the issues that you have to decide when you create a style property for your
component is how to set its default value. Setting a default value for a style property is not as
simple as calling the
setStyle()
consideration how Flex processes styles, and the order of precedence of styles.
When Flex compiles your application, Flex first examines any style definitions in the
tag, before it creates any components. Therefore, if you call
<mx:Style>
within the component's constructor, which occurs after processing the
set the style property on each instance of the component; this overrides any conflicting CSS
declarations in the
<mx:Style>
The easiest way to set a default value for a style property is to define a static initializer in your
component. A static initializer is executed once, the first time Flex creates an instance of a
component. In
"Defining a style property" on page
using the
classConstructed
StyledRectangle.as class.
The
classConstruct()
component. This method determines a style definition for the StyledRectangle class already
exists, defined by using the
method creates one, and sets the default value for the style property.
Therefore, if you omit the
created by the
classConstruct()
<?xml version="1.0"?>
<!-- skinstyle\MainRectNoStyles.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:StyledRectangle/>
</mx:Application>
192
Creating Custom Style Properties
method in the component's constructor; you must take into
tag.
variable and the
method is invoked the first time Flex creates a StyledRectangle
tag. If no style is defined, the
<mx:Style>
tag from your application, the style definition is
<mx:Style>
method, as the following example shows:
189, you defined a static initializer, by
method, as part of the
classConstruct()
from
setStyle()
tag, you
<mx:Style>
classConstruct()

Advertisement

Table of Contents
loading

Table of Contents