@Resource directive doesn’t work with mx:SetProperty?
There’s a compile-time mechanism in Flex for getting values out of .properties files instead of directly in the ActionScript and MXML code. In MXML, you use the @Resource directive and specify a key, and the compiler handles the messy details of figuring out the right .properties file to use based on the locale. This works fine most of the time, but there seems to be a problem when you try to use @Resource to assign a string value to a property of type *. Consider mx:SetProperty, whose value property is of type *. If you write the following in your MXML:
<mx:SetProperty target="{txtBottom}" name="text" value="@Resource(key='SENDING')"/>
You’ll get a couple of compiler errors:
1067: Implicit coercion of a value of type String to an unrelated type Number. 1119: Access of possibly undefined property get through a reference with static type mx.resources:ResourceBundle.
And if you check out the generated .as file corresponding to the MXML file, you’ll see the following line of code:
temp.value = rb_InternalErrorDlgLayout.get*("SENDING");
Notice that get*() call. I’m guessing that’s a bug in the MXML-to-ActionScript converter. The variable rb_InternalErrorDlgLayout is an instance of ResourceBundle, which has methods getString(), getStringArray() getBoolean(), getNumber(), and getObject(), but of course no get*() method. I suspect that if the MXML-to-ActionScript converter generated getObject() instead of get*(), it would probably all just work.
My workaround was to make a subclass of mx:SetProperty, SetPropertyString, with a valueString property. That worked fine.
Technorati Tags: ActionScript, Flex




Thanks for pointing this out. I ran in to the same problem and you post was the only relevant that came up when I googled for “mx:SetProperty @Resource”.
You probably saved me from at least an hour’s meaningless work trying to find out why it didn’t work and how to solve it. Thanks!
You’re very welcome!