Specifications
CHAPTER 4
76
The weakRef parameter to the addEventListener() method provides you with some control over memory
resources for listeners. A strong reference (when
weakRef is false) prevents the listener from being garbage
collected. A weak reference (when
weakRef is true) does not. The default is false.
For more information about the
removeEventListener() method, see “Using Events” on page 61 in the Adobe
Flex 3 Developer Guide.
Using styles
You use styles to define the look and feel of your Flex applications. You can use them to change the appearance of
a single component, or apply them globally. Be aware that some methods of applying styles are more expensive
than others. You can increase your application’s performance by changing the way you apply styles.
For more information about using styles, see “Using Styles and Themes” on page 589 in the Adobe Flex 3
Developer Guide.
Loading stylesheets at run time
You can load stylesheets at run time by using the StyleManager. These style sheets take the form of SWF files that
are dynamically loaded while your Flex application runs.
By loading style sheets at run time, you can load images (for graphical skins), fonts, type and class selectors, and
programmatic skins into your Flex application without embedding them at compile time. This lets skins and fonts
be partitioned into separate SWF files, away from the main application. As a result, the application’s SWF file size
is smaller, which reduces the initial download time. However, the first time a run-time style sheet is used, it takes
longer for the styles and skins to be applied because Flex must download the necessary CSS-based SWF file.
For more information, see the Adobe Flex 3 Developer Guide.
Reducing calls to the setStyle() method
Run-time cascading styles are very powerful, but use them sparingly and in the correct context. Calling the
setStyle() method can be an expensive operation because the call requires notifying all the children of the
newly-styled object. The resulting tree of children that must be notified can be quite large.
A common mistake that impacts performance is overusing or unnecessarily using the
setStyle() method. In
general, you only use the
setStyle() method when you change styles on existing objects. Do not use it when you
set up styles for an object for the first time. Instead, set styles in an
<mx:Style> block, as style properties on the
MXML tag, through an external CSS style sheet, or as global styles.










