views:

677

answers:

1

Hi,

Flex 3 question:

I trying here to avoid having to bind resources to all my components labels ( ie a button) and find a way to have this automated.

Problem: It corrupts the layout in design mode to bind directly in the mxml label="{resourceManager.getString('myResources', 'submit')}" and makes the design view useless. but when declaring bindings elsewhere, in actionScript or via a bind tag, it is counter productive and prone to many errors and miss.

Proposition: I would like to create my own button that automatically invoke resources to localize a button label. So the author puts "Submit" in the mxml description of my button, and when running it would take the value of the label ie "submit" and use resourceManager.getString('myResources', 'submit').

but I can't find the way to override the set label function, Is it possible if yes how? else how can I go about it?

Maybe I am missing an essential process here that would make the use of resources more elegant, as well as how to override such thing as a button's label.

Thanks for your advices.

+1  A: 

Create a component called MyButton, extending Button. Then use this:

override public function set label(value:String):void {
  super.label = resourceManager.getString('myResources', value) || value;
}

Assuming the resource manager returns "null" or "undefined" this will work, and will only replace the value if it exists in "myResources".

If you don't want to override every component you need to do this with, then you can add a FlexEvent.CREATION_COMPLETE event on every component. Then use a single generic function to do your label localization.

Glenn
thank you!Have a good day
Jean Fabre