13 Replies Latest reply on Aug 31, 2009 4:34 AM by Shivik

    Problem in localization in a MenuBar control in Flex 3

    Shivik Level 1

      Hello all

       

      I am trying to create a localized menubar in Flex 3. I am able to do  that. But it has a flaw. The thing is that some of submenu-items are not being
      displayed when the page loads. Here's how it looks right now...

       

      1. When page loads

       

      screenshot2.jpg  screenshot3.jpg

       

       

      2. After changing the localization, everything is displayed fine.

       

      screenshot4.jpg

       

       

      What could be going wrong here?

       

      Thanks and Regards

      Vikram

        • 1. Re: Problem in localization in a MenuBar control in Flex 3
          Barna Biro Level 3

          What do you mean by "when the page loads"? How does loding come into the picutre and why would loading affect the menu elements? Maybe you are just validating the component after modifying it and that's why it's not displayed correctly. I'm guessing that "once the loading has complete" a validateNow(); or some other validation event is being triggered that is re-rendering your components and that's why you then see the menu bar items correctly.

          1 person found this helpful
          • 2. Re: Problem in localization in a MenuBar control in Flex 3
            Shivik Level 1

            @ Barna Biro

             

            Ummm I haven't used any validation event as such which might re-render the page.

             

            Let me give a little clue that I have uncovered about what is happening.

             

            No. of items not displayed in nth menu = No. of items in (n+1)th menu

             

             

            In the example that I have shown,

            Menu # 2 ( "Menu1" ) has 6 sub-items.

            Menu # 3 ( "Menu2" ) has 3 sub-items.

            Hence, No. of sub-items not displayed in Menu # 2 = No. of items in Menu # 3 = 3

             

            Does this make any sense at all?

             

            Thanks and Regards

            Vikram

            • 3. Re: Problem in localization in a MenuBar control in Flex 3
              Barna Biro Level 3

              Shivik wrote:


              Does this make any sense at all?

               

              Sadly, not really. I do believe that this has to do with validation ( you didn't use any validation methods until now because most of the time, the player does this for you... certain methods automatically invalidate and later on validate your components or the entire view - "behind the scenes" stuff ). Read up on validaDisplayList(); validateProperties(); validateSize(); and validateNow();

               

              Or, you could try reproducing the problem in a new project so that we can work on that dirrectly and help find a solution much faster ( still, I believe that the reason why you are not seeing the component correctly is because it has not been validated on time ).

              1 person found this helpful
              • 4. Re: Problem in localization in a MenuBar control in Flex 3
                Shivik Level 1

                @ Barna Biro

                Or, you could try reproducing the problem in a new project

                Yes that sounds like a good idea. I will try and see whether the problem is occuring because of other components or services or not.

                 

                Thanks and Regards

                Vikram

                • 5. Re: Problem in localization in a MenuBar control in Flex 3
                  Shivik Level 1

                  I tried creating a new project but the problem remains the same.

                   

                  I used the following wiki on adobe labs.

                   

                  http://labs.adobe.com/wiki/index.php/Flex_3:Feature_Introductions:_Runtime_Localization

                   

                  I just used the MenuBar control instead of the Label the tutorial is using. The script is exactly the same. But it is giving the same problem. I am going to look into the Validation methods for some answers. Although I have some experience in that, but I don't know what happens in validation of MenuBar control.

                   

                  Thanks and Regards

                  Vikram

                  • 6. Re: Problem in localization in a MenuBar control in Flex 3
                    Barna Biro Level 3

                    Could you export the test project you created as a .zip file and upload it? I'm sorry but I don't have the time to read all that, so taking a look at the project would be of much more help. Thanks.

                    • 7. Re: Problem in localization in a MenuBar control in Flex 3
                      Shivik Level 1

                      @ Barna Biro

                       

                      Ok I am uploading the test project as a zip file.Thanks for looking into it.

                       

                      One more thing to run the project, here is copylocale command....

                      Set the current directory to the Flex SDK that your Flex Builder project is using. By default, this will be the directory sdks/3.0.0 inside your Flex Builder installation. Now execute

                      bin\copylocale.exe en_US jp_JP

                      on Windows or

                      bin/copylocale.sh en_US jp_JP

                      on Macintosh

                       

                      And the compiler settings...

                      Change the -locale option to be

                      -locale=en_US,jp_JP -source-path=../locale/{locale}

                       

                      Thanks and Regards

                      Vikram

                      • 8. Re: Problem in localization in a MenuBar control in Flex 3
                        Barna Biro Level 3

                        Please upload the archive to http://www.mediafire.com/ and leave a link. I'm afraid that it will take ages until Adobe aproves your uploaded archive and I don't think you are willing to wait that long. And don't worry, this ain't the first time I see local resources in action but thanks for the hints.

                        • 9. Re: Problem in localization in a MenuBar control in Flex 3
                          Shivik Level 1

                          I think the zip file has been approved on Adobe forums. It is displaying for download. Meanwhile, I am setting up things on mediafire just in case.

                          • 11. Re: Problem in localization in a MenuBar control in Flex 3
                            Barna Biro Level 3

                            Ohh, the aproval was fast this is a new one.

                             

                            So, the solution:

                             

                            <?xml version="1.0" encoding="utf-8"?>
                            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                                 
                                 <mx:Metadata>
                                    [ResourceBundle("resources")]
                                </mx:Metadata>
                                
                                 <mx:Script>
                                      <![CDATA[
                                      
                                           import flash.events.Event;
                                           
                                           // Defining the locales for the system
                                           [Bindable]
                                           private var locales:Array = ["en_US", "jp_JP"];
                                           
                                           private function cmbLocale_initHandler(event:Event):void
                                           {
                                                cmbLocale.selectedIndex = locales.indexOf(resourceManager.localeChain[0]);
                                           }
                                           
                                           private function cmbLocale_changeHandler(event:Event):void
                                           {
                                                resourceManager.localeChain = [ cmbLocale.selectedItem ];
                                           }
                                      ]]>
                                 </mx:Script>
                                 
                                 <mx:XMLList id="xmlData">
                                    <menuitem label="{resourceManager.getString('resources', 'Menu0')}"/>
                                    <menuitem label="{resourceManager.getString('resources', 'Menu1')}">
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu11')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu12')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu13')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu14')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu15')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu16')}"/>
                                    </menuitem>
                                    <menuitem label="{resourceManager.getString('resources', 'Menu2')}">
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu21')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu22')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu23')}"/>
                                    </menuitem>
                                    <menuitem label="{resourceManager.getString('resources', 'Menu3')}">
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu31')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu32')}"/>
                                    </menuitem>
                                    <menuitem label="{resourceManager.getString('resources', 'Menu4')}"/>
                                    <menuitem label="{resourceManager.getString('resources', 'Menu5')}">
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu51')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu52')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu53')}"/>
                                        <menuitem label="{resourceManager.getString('resources', 'SubMenu54')}"/>
                                    </menuitem>
                                </mx:XMLList>
                                 
                                 <mx:ComboBox id="cmbLocale" dataProvider="{locales}" initialize="cmbLocale_initHandler(event)" change="cmbLocale_changeHandler(event)"/>
                                 <mx:MenuBar id="menuBar" labelField="@label" dataProvider="{xmlData}"/>
                            </mx:Application>
                            

                             

                            Just take the XML structure out of the component. Having it declared withing the component is not really good in such situations because the structure might not be initialized correctly ( the resource manager may not be instantiated correctly or the structure might not have correct access to it - there are quite a few issues that might come into play ).

                            • 12. Re: Problem in localization in a MenuBar control in Flex 3
                              Shivik Level 1

                              Oh no...now I get it.The problem dates back to the day I took the XML data out of actionscript and moved it inside mxml. Now, that teaches me a lesson to go to my dear-old version control .

                               

                              Thanks for going through the trouble.

                               

                              With Best Regards

                              Vikram