flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Russell Warren <r...@perspexis.com>
Subject Re: Using FlexGlobals.topLevelApplication in class init code (or: "how do you set default styles for an AS3 component?")
Date Mon, 03 Dec 2012 16:50:26 GMT
Thanks for the quick response...

On Mon, Dec 3, 2012 at 11:17 AM, Alex Harui <aharui@adobe.com> wrote:

> 1. FlexGlobals.topLevelApplication points to the Application instance, so
> it
> can't be assigned until the Application is instantiated, which requires
> that
> the class and instance initializers for Application get run.  If one of
> those things requires your custom class, then your class initializers will
> get run before topLevelApplication can get set.  So, using FlexGlobals in
> class initializers is not guaranteed to work.

I wondered if it was something like this, thanks.  It seems it was luck
that it worked before, or something changed in the higher level application
that required earlier component instantiation.

I will now stay away from FlexGlobals in class initializers!

> 2. In the most general case, styles should get applied per moduleFactory.
> Your style initializers are assuming that the styles should always apply to
> the topLevelApplication.  In really large, multi-swf apps, this kind of
> code
> can fail to work correctly.  But hey, if you are only writing single-swf
> apps, then something like this will work.

This will definitely be used in a large multi-swf/Module application.  I'm
just after the right way to set defaults, regardless of application scope.

> For the general case, the recommended practice is to declare a CSS
> type-selector for the component.  If you bundle the component in a SWC,
> then
> you include the CSS in the swc.

Does this mean that *every* style property of *every* component in Flex has
a matching CSS assignment in a CSS file somewhere in the Flex library?
 What if you miss one?  What default is then used?

If you want to make the assumption that you can get away with shoving the
> styles into the top-level Application's StyleManager, I think you can just
> call StyleManager.getStyleManager(null).

Interesting/awesome - I changed the code to
use StyleManager.getStyleManager(null) and what was broken is now
functioning again:

Will this be "guaranteed to work" in a class initializer (whereas
FlexGlobals won't), or am I rolling the dice again here?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message