RE: [flexcoders] BindingUtils and ResourceManager Question
Thanks for the suggestions, Johannes. Unfortunately, using an explicit event won't scale well in a big application since every access of a resource string from ActionScript will require this treatment. I've done a -keep-generated-actionscript and tried to grok the ActionScript code the Flex compiler generates when specifying a data binding in MXML and it just doesn't make sense to me just yet. I'm still on the hunt for a code sample using a ChangeWatcher or some means to set up the binding without explicit events. My objective is a single line of code just like using BindingUtils.bindProperty. It seems like I should be able to write a similar class as BindingUtils and expose an API that takes a Function as the chain property, instead of an Object. Anyway, thanks for your suggestion. Erik From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Johannes Nel Sent: Wednesday, January 28, 2009 4:01 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] BindingUtils and ResourceManager Question on rereading your post i realise that what you are after is change events (but my post will also help a bit me thinks) a few people did custom annotations which function like an event listener, just google a bit, i think it will make your life easier. old post/// ok, i will approach it slightly differently. I would use a presentation model to bind the text to, so component control text=presModel.someText/ /component in my pres model class presModel { [Bindable(localChange)] [Bindable (someTextChange)] public function get someText():String [Bindable(localChange)] [Bindable (someOtherTextChange)] public function get someOtherText():String } this way you have groups of text that update at the same time when your local changes (which in the workflow we use would look something like this (still inside this presModel) [Trigger (path=myModel.theLocalleValueIWantToKnowAbout)] public function set localle(localle:String) { dispatchEvent(localChange) } where this localChange event will update all the strings which have a bindable declared with that custom event name. the trigger annotation is basically an event listener and is the same as saying in my local presentation model notify me when the applications localle changes, thus someAppModel.addEventListener(localChange) jpn On Wed, Jan 28, 2009 at 12:09 AM, Thomas, Erik erik_tho...@intuit.com mailto:erik_tho...@intuit.com wrote: Having just localized a medium sized application into Spanish, I ran into a recurring pattern I had to work around that I really shouldn't have to, specifically around data binding localized resources from ActionScript. For example, in MXML, one can data bind a localized resource and when the localeChain is switched dynamically, all bound clients will requery their values and the new language will display: mx:Label text={resourceManager.getString(ResourceEnums.COMMON, 'labelAppointments}/ When the localeChain is switched, the label above will automatically update to the Spanish version, just like magic. This is a very cool feature of Flex 3 resource management. However, there are many use cases where I need to bind to resource bundles from within ActionScript, sort of like this: public class Foo { [Bindable] public var bar:String; public function Foo() { bar = ResourceManager.getString(ResourceEnums.COMMON, 'labelAppointments'); } } When the localeChain is updated, bar is obviously not automatically updated because bar is not bound to the resource, it is just a simple assignment. BindingUtil.bindProperty and bindSetter don't appear to offer parameters that will work with ResourceManager. I've experimented a little, but it does not appear possible to use BindingUtils to bind to a resource. I had to work around this by listening for a localeChange event and then reassigning the resource to the variable. This does not scale. So my question is simple: can you bind a variable to a resource in ActionScript? If so, how? Thanks! Erik Erik Thomas | Small Business Group, Intuit | Staff Engineer | 650-944-2602 -- j:pn \\no comment
RE: [flexcoders] BindingUtils and ResourceManager Question
HI Yves: This is a great suggestion! It's pretty readable and doesn't require changes anywhere else but where you instantiate the property. I will write a class to manage this, though we can't refactor our MXML (way too much code) to use the same mechanism. This will just be for those use cases where we need to bind in ActionScript which is fortunately a pretty small percentage. Thank you! Erik From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Yves Riel Sent: Wednesday, January 28, 2009 6:50 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] BindingUtils and ResourceManager Question What we have done is to separate ourselves from the resource manager a bit. We have created a new class that basically has a bindable property called value. This class is passed the name of the string that is localized in the resource manager and hooks to the resource manager. It monitor for changes on the resource manager and when they are detected, the class sends an event that triggers the binding. So, it can be used directly in MXML or in the .as file by using the BindingUtils class. In pseudo code (.as file): var localizedProp:LocalizedProperty = LocalizedProperty.create(Bundle, localized property); BindingUtils.bindProperty( this, your variable, localizedProp, value); In pseudo code (.mxml file): [Bindable] var localizedProp:LocalizedProperty = LocalizedProperty.create(Bundle, localized property); mx:label text={localizedProp.value}/ http://geo.yahoo.com/serv?s=97359714/grpId=12286167/grpspId=1705007207/ msgId=135445/stime=1233144154/nc1=4507179/nc2=3848640/nc3=4836040
[flexcoders] BindingUtils and ResourceManager Question
Having just localized a medium sized application into Spanish, I ran into a recurring pattern I had to work around that I really shouldn't have to, specifically around data binding localized resources from ActionScript. For example, in MXML, one can data bind a localized resource and when the localeChain is switched dynamically, all bound clients will requery their values and the new language will display: mx:Label text={resourceManager.getString(ResourceEnums.COMMON, 'labelAppointments}/ When the localeChain is switched, the label above will automatically update to the Spanish version, just like magic. This is a very cool feature of Flex 3 resource management. However, there are many use cases where I need to bind to resource bundles from within ActionScript, sort of like this: public class Foo { [Bindable] public var bar:String; public function Foo() { bar = ResourceManager.getString(ResourceEnums.COMMON, 'labelAppointments'); } } When the localeChain is updated, bar is obviously not automatically updated because bar is not bound to the resource, it is just a simple assignment. BindingUtil.bindProperty and bindSetter don't appear to offer parameters that will work with ResourceManager. I've experimented a little, but it does not appear possible to use BindingUtils to bind to a resource. I had to work around this by listening for a localeChange event and then reassigning the resource to the variable. This does not scale. So my question is simple: can you bind a variable to a resource in ActionScript? If so, how? Thanks! Erik Erik Thomas | Small Business Group, Intuit | Staff Engineer | 650-944-2602
Re: [flexcoders] BindingUtils and ResourceManager Question
on rereading your post i realise that what you are after is change events (but my post will also help a bit me thinks) a few people did custom annotations which function like an event listener, just google a bit, i think it will make your life easier. old post/// ok, i will approach it slightly differently. I would use a presentation model to bind the text to, so component control text=presModel.someText/ /component in my pres model class presModel { [Bindable(localChange)] [Bindable (someTextChange)] public function get someText():String [Bindable(localChange)] [Bindable (someOtherTextChange)] public function get someOtherText():String } this way you have groups of text that update at the same time when your local changes (which in the workflow we use would look something like this (still inside this presModel) [Trigger (path=myModel.theLocalleValueIWantToKnowAbout)] public function set localle(localle:String) { dispatchEvent(localChange) } where this localChange event will update all the strings which have a bindable declared with that custom event name. the trigger annotation is basically an event listener and is the same as saying in my local presentation model notify me when the applications localle changes, thus someAppModel.addEventListener(localChange) jpn On Wed, Jan 28, 2009 at 12:09 AM, Thomas, Erik erik_tho...@intuit.comwrote: Having just localized a medium sized application into Spanish, I ran into a recurring pattern I had to work around that I really shouldn't have to, specifically around data binding localized resources from ActionScript. For example, in MXML, one can data bind a localized resource and when the localeChain is switched dynamically, all bound clients will requery their values and the new language will display: mx:Label text={resourceManager.getString(ResourceEnums.COMMON, 'labelAppointments}/ When the localeChain is switched, the label above will automatically update to the Spanish version, just like magic. This is a very cool feature of Flex 3 resource management. However, there are many use cases where I need to bind to resource bundles from within ActionScript, sort of like this: public class Foo { [Bindable] public var bar:String; public function Foo() { bar = ResourceManager.getString(ResourceEnums.COMMON, 'labelAppointments'); } } When the localeChain is updated, bar is obviously not automatically updated because bar is not bound to the resource, it is just a simple assignment. BindingUtil.bindProperty and bindSetter don't appear to offer parameters that will work with ResourceManager. I've experimented a little, but it does not appear possible to use BindingUtils to bind to a resource. I had to work around this by listening for a localeChange event and then reassigning the resource to the variable. This does not scale. So my question is simple: *can you bind a variable to a resource in ActionScript? If so, how?* Thanks! Erik *Erik Thomas* | Small Business Group, *Intuit* | Staff Engineer | 650-944-2602 -- j:pn \\no comment
RE: [flexcoders] BindingUtils and ResourceManager Question
What we have done is to separate ourselves from the resource manager a bit. We have created a new class that basically has a bindable property called value. This class is passed the name of the string that is localized in the resource manager and hooks to the resource manager. It monitor for changes on the resource manager and when they are detected, the class sends an event that triggers the binding. So, it can be used directly in MXML or in the .as file by using the BindingUtils class. In pseudo code (.as file): var localizedProp:LocalizedProperty = LocalizedProperty.create(Bundle, localized property); BindingUtils.bindProperty( this, your variable, localizedProp, value); In pseudo code (.mxml file): [Bindable] var localizedProp:LocalizedProperty = LocalizedProperty.create(Bundle, localized property); mx:label text={localizedProp.value}/ http://geo.yahoo.com/serv?s=97359714/grpId=12286167/grpspId=1705007207/ msgId=135445/stime=1233144154/nc1=4507179/nc2=3848640/nc3=4836040