10 Replies Latest reply on Jun 25, 2007 10:02 PM by cheftimo

    Custom Component/Resource Bundle problem

    cheftimo Level 2
      Basically, here is the problem:

      I have a public function defined in the main MXML app. I want to use that function everywhere in the application, but I’m not having any luck getting the compiler to see it if I use it in a Custom Component.

      I started a tread for this in the Flex Builder 2 forum. So far, no results, plus that thread is getting way too long and this forum seems more appropriate for this subject. For those interested, here is the original thread: http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=582&threadid =1238407&enterthread=y.

      I hope to hear from someone about this.

        • 1. Custom Component/Resource Bundle problem
          What I found to work is to:

          1. Create a new folder in your Application. Personally, I would call it "ActionScript"!

          2. Right-click the newly created folder and select New>ActionScript File.

          3. Cut the public function that is in the Script block of your Main.mxml file and paste it into the .as file.

          4. Then copy and paste the following code after the opening tag of your Main Application and after the opening tag of every component that needs to call your public function...

          <mx:Script source="../actionScript/TheNameOfYourFileHere.as" />

          5. Then you can call ANY function in your .as file.

          Let me know if this helps!!!

          • 2. Re: Custom Component/Resource Bundle problem
            cheftimo Level 2

            Thanks very much for your reply – your suggestion did help, we have made a little progress.

            There is a small complication: the language change is made by using a ComboBox. The only way I could get this to work was by adding the ComboBox itself to the Custom Component. I tried declaring a var in a Script block like this: ‘public var lang:ComboBox’, but that didn’t do anything. Of course, I would like to just have the ComboBox in just one place and have it be able to change the language in the entire app.

            If you – or anybody else – want(s) to take the time to look, you can see this thing here: http://www.timos.com/coiBI/coinoniaBI.html. View Source is enabled, even the debug files are there.

            I imagine eventually I’ll get this right; it sure has been a long ride.

            Thanks again,

            • 3. Re: Custom Component/Resource Bundle problem
              jpwrunyan Level 1

              Just to let you know, I am not ignoring your thread. But I am giving up on this for now. To reiterate, I do not think the problem is with ResourceBundle. I think the problem is just that binding is not supported the way Jeff Tapper thinks it is. He is basically using a "hack" that works for his simple demo application but unfortunately does not work for yours. You might send him a mail telling him that. But according to the official docs that I quoted yesterday, only variables and getter/setters can be bound. Binding to methods (when it does work) is simply bad practice.

              Anyway, for you to implement your application the way you want to, you are going to need to change the code logic radically. This is more a design/creativity issue instead of a technical one so I will leave it to you to come up with your own idea that suits your needs. If you have questions after that, post them. One thing I might suggest is finding a way to get the parameter information you are submitting as a method argument from within the method as opposed to passing it as an argument. Then you can implement your method as a getter instead of a normal function (this is a very dumbed-down example of your original code):

              function getText(key:String):String {
               return languageData[key];
              the above doesn't work because Bindable isn't fully supported for a "normal" function.

              [Bindable (event="langChange")]
              function get text():String {
               var key:String = getTheKeyFromSomewhereSomehow();
               return langData[key];
              since the above is a getter method, Binding is fully supported even when called from children:
              <mx:Text text="{parentDocument.text}" />

              So as you can see, the hat-trick is to have one getter method that will return a value dynamically which is appropriate to each component. You are going to need to radically change things and I don't see an easy solution... but I am sure with some careful thought and planning it could be done. But it will take a lot of time and concentration--even for an expert AS programmer. Maybe Mr. Tapper should make this the topic of his next blog.
              • 4. Custom Component/Resource Bundle problem
                JohnLeger Level 1

                I download the source and opened it in Flex 2. There is absolutely a way to do what you are wanting to do. When I have time I'll try to check out your code.

                May I recommend that you delete the backgroundColor="#990000" property on your mxml components. You have the same backgroundColor="#990000" on your CoinoniaBI.mxml. By placing the same color on your mxml components the component is showing up a sligtly lighter color.

                By the way I notice this is a Christian application you are building. Is it for yourself or for a client? I am a senior pastor of a church in Maryland who loves to relieve stess by FLEXING. Also you may want to know that the Greek for fellowship is Koinonia, with a 'K' not a 'C'. Below is some info from a Strongs Concordance on the Greek word. :)

                Strongs NT:2842
                koinonia (koy-nohn-ee'-ah); from NT:2844; partnership, i.e. (literally) participation, or (social) intercourse, or (pecuniary) benefaction:

                Used in the KJV - (to) communicate (-ation), communion, (contri-) distribution, fellowship.

                (Biblesoft's New Exhaustive Strong's Numbers and Concordance with Expanded Greek-Hebrew Dictionary. Copyright © 1994, 2003, 2006 Biblesoft, Inc. and International Bible Translators, Inc.)


                • 5. Re: Custom Component/Resource Bundle problem
                  cheftimo Level 2
                  Jpwrunyan, JohnLeger, et al:

                  The answers/hints I have received since I started these threads (both in the FB2 Forum and in this one) have been a huge help and are very much appreciated. And this subject - I18N/multilanguage and things related - should be of interest to many. I find it odd that, in this country, where there is a number of enormous ethnic groups, the subject is so often overlooked; after all, that is what ‘www’ is all about.

                  I imagine I will get this thing down in the near future, with a lot of study. I am a newbie, and I suspect there are many more of us; so any pointers to information that you gurus can provide, will help. I myself am at the stage where “getters and setters” might as well be Sanscript: 90% of the references I have found to that topic are to Java, which I thought was something you drink in the morning.

                  But please, keep the hints/tips coming; they won’t be wasted!

                  JohnLeger, I wanted to tell you more about “coinonia” but did not find an e-mail address in your profile. Please send me one if you are interested in knowing more about that theme.

                  Any of the participants in these forums are welcome to contact me directly.

                  Thanks again,

                  Carlos Corredor – carlos@timos.com
                  • 6. Re: Custom Component/Resource Bundle problem

                    I am trying to do the same thing you tried: Change the language of the the Flex app I am building at runtime. I also used Jeff Tapper's solution and, like you, it worked great on the main app but I cannot get it to change the language of any child custom components. Like you, I am new to Flex and with no Java programming. I'm a designer with good HTML, javascript skills and a smattering of PHP.

                    Did you ever get this working to your satisfaction, and if so would you mind sharing your solution?

                    Thanks alot,
                    Jack O'Melia
                    • 7. Re: Custom Component/Resource Bundle problem
                      cheftimo Level 2
                      Hello, Jack:

                      No, I have not yet resolved this to my satisfaction. At this point, this is a study project, I don’t have a deadline. Right now, as time permits, I am working on a custom event and one or two other things that may be the answer. I also plan to really study the ResourceBundle class word by word.

                      The minute I come up with something that works, I’ll post it here – you please do the same. We’ll get this thing solved.


                      • 8. Re: Custom Component/Resource Bundle problem
                        David Ethell
                        Timo, I'm wrestling with the same problem. Here's how I worked around it for now:

                        In the custom component I declared a bindable variable of type function:

                        public var geti18nText : Function;

                        Then in the parent app I have to assign the parent i18n function to the component local funtion (very ugly, I know):

                        customComponent.geti18nText = geti18nText;

                        That is overly cumbersome for a large application with lots of components so I do not consider this a solution, but we have it as a workaround until we find a better way to localize our apps at runtime.


                        • 9. Re: Custom Component/Resource Bundle problem
                          cheftimo Level 2
                          Hello David, thanks for replying.

                          This subject seems to be a sommmbitch. Since I started this post (and a previous one in the FlexBuilder 2 forum, I have had replies from a bunch of people, seemingly advanced programmers, including ‘peterent’ of Adobe. None of the suggestions they made worked and they all walked away from the topic.

                          I take it you are doing this based on the example in Jeff Tapper’s blog, using the ComboBox change event to change the language?

                          I still have not been able to make it work. In addition to what you suggest
                          customComponent.geti18nText = “geti18nText”;

                          I also tried
                          customComponent.geti18nText = “{geti18nText}”;

                          I used the double quotes, which you do not show, because the compiler gave me and error message to that effect – (I’m working with FB 2.01)

                          I have also tried declaring the ResourceBundle in the component (it’s already in the main app, as in Jeff’s example).

                          So, my question is: is it working for you just doing what you suggested, or have you done other things in addition?

                          If you have time, please tell me anything that you think might help.

                          Best regards,


                          PS Anyone else want to get in on this action?
                          • 10. Re: Custom Component/Resource Bundle problem
                            cheftimo Level 2
                            Hello, all -

                            For those of you who may still be interested in this topic, I consider this good news: Flex 3 Beta 1.

                            Flex 3 now supports runtime language switching. It has a new ResourceManager that handles access to the localized resources in the application.

                            Although the documentation for this Beta is completely messed up – broken on the web and not yet updated in the FB3 help, you can find a good article in Adobe Labs: Flex 3>Feature Introductions>Runtime Localization.

                            There are 2 sample projects you can download and import into FB3 in which there is a lot to chew on, but the article provides a step-by-step tutorial on building a very simple project, which gives you a good intro to the new features.

                            I expanded on this simple tutorial a little bit, adding a custom component that displays localized resources on labels. All I had to do was add the custom component to the main app, and it all works fine!

                            Try it, you’ll like it!