> I can control neither code that was written before I started working on this 
> project nor all design decisions

But if you point out that one of the Flex SDK engineers said "don't do that", 
maybe they won't do it any more. :)

Gordon Smith
Adobe Flex SDK Team

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Tim Rowe
Sent: Monday, June 01, 2009 5:34 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Resource bundles and static vars




That's exactly along the line I was looking at the problem being, though could 
only cofirm this through observed behavior rather than any actual underlying 
evidence.  In the mantime I've been looking at the problem and I've managed to 
switch the culprits to member variables (they had quite a few references to 
them from other classes as statics).

The idea you've mentioned of using the accessor is one I hadn't considered - 
quite a neat trick for getting around this.  I certainly agree on trying to 
avoid the use as you said - unfortunately I can control neither code that was 
written before I started working on this project nor all design decisions, 
regardless of how much I might object :)

Thanks for the confirmation,

--Tim

________________________________
From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Gordon Smith
Sent: Tuesday, 2 June 2009 10:26 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Resource bundles and static vars
Reources are not loaded into the ResourceManager early enough for use at static 
initialization time. If you want a resource-based public static foo, do 
something like
private static var _foo:String;
public static function get foo():String
{
    if (_foo == null)
        _foo =ResourceManager.getInstance().getString(...);
    return _foo;
}
so that foo is initialized just-in-time from a resource on first access.
In general, it's dangerous to have the static initialization value of something 
in one class depend on anything in another class, because the order in which 
classes get initialized is hard to figure out and you might have 
circular-dependencies.
Just-in-time initialization is a good general solution to these problems, at 
the cost of a simple null check on each access.
Gordon Smith
Adobe Flex SDK Team
From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Manish Jethani
Sent: Monday, June 01, 2009 5:18 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Resource bundles and static vars





Try putting a breakpoint in SystemManager's
installCompiledResourceBundles() function. That's where the resource
bundles are set up.

It's possible that your class is being loaded before the resource
bundles are set up, and that's why you're getting null.

Manish

On Tue, Jun 2, 2009 at 5:08 AM, Tim Rowe 
<tim.r...@carsales.com.au<mailto:tim.rowe%40carsales.com.au>> wrote:
>
>
> I'm trying to resolve an issue whereby we have a heap of structures defined
> in static arrays, and one of the params is a string of text.  Ideally this
> string would come from a resource bundle to allow localization on the
> string.
>
> The problem is that though I've tried a variety of methods, I cannot get any
> resouce bundle values into this variable.
>
> Effectively the code I have is
> public static const foo =
> ResourceManager.getInstance().getString('myBundle', 'myKey');
> Although it's a little more glammed up than that (but I've tried it in this
> basic form). In the attempts I've gone as far as to even try having a
> utility class which calls out to a singleton, but even within that singleton
> when accessed via a static all values and ResourceBundles from
> ResourceManager come back as null values.
>
> None of the other mxml elements seem to have issues reading the same
> resource bundle - when addressed via @Resource(bundle='foo', key='bar') and
> similar they all find the values in the .properties file just fine.
> Unfortunately the nature of these variables makes it highly preferable
> they're left as statics, though it is beginning to appear that might not be
> viable.
>
> Would anyone have any suggestions on this?  It's not the first time I've had
> this problem, but last time we just gave up trying from memory.  Is it just
> a case that the ResourceBundles aren't loaded and accessable at the time
> statics are initialised, or is there something more simple (or perhaps more
> sinister?) going on?
>
> Thanks,
>
> Tim Rowe
> Software Engineer
> carsales.com Ltd
>
> Level 1, 109 Burwood Road
> Locked Bag 3333
> Hawthorn VIC 3211
>
> t: 03 9093 8600 (Reception)
> t: 03 9093 8757 (Direct)
> f: 03 9093 8697
>
>
>

Reply via email to