aharui commented on issue #824:
URL: https://github.com/apache/royale-asjs/issues/824#issuecomment-629754994


   I pushed some changes to that changing XMLListCollection.source will update 
the MenuBar.  I'm not clear on what your restrictions are in terms of updating 
the XMLListCollection, but updating the source in this example works.
   
   ```
   <?xml version="1.0" encoding="utf-8"?>
   <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
                           xmlns:s="library://ns.apache.org/royale/spark"
                           xmlns:mx="library://ns.apache.org/royale/mx"
                           paddingBottom="0" paddingTop="0" paddingLeft="0" 
paddingRight="0"
                           creationComplete="init()"
                           height="100%" width="100%" 
                           >
        <fx:Metadata>
                [ResourceBundle("containers")]
        </fx:Metadata>
        <fx:Declarations>
                        <mx:XMLListCollection id="menuBarData2" 
source="{menuDataXMLList}"/>    
        </fx:Declarations>
        
        <fx:Script>
                <![CDATA[
                        
                        import org.apache.royale.events.ValueChangeEvent;
                        import mx.resources.ResourceManager;
                        import mx.collections.XMLListCollection;
                        import mx.events.FlexEvent;
                        import mx.events.MenuEvent;
                        
                        
                                
                        protected function 
creationCompleteHandler2(event:FlexEvent):void
                        {
   
                                var roleInfo:String = "ADMIN";
                                
                                /*
                                var tmpXmlList:XMLListCollection = new 
XMLListCollection();
                                tmpXmlList.source = menuDataXMLList;
                                
                                menuDataXMLList = tmpXmlList.source.copy();
                                
                                menuBarData2.source = menuDataXMLList;
                                
                                menuBarData2.refresh();
                                */
   
                        }
                        
                        protected function 
itemClickHandler(event:MenuEvent):void {
                        }
                        
                        private function init():void {
                                resourceManager.localeChain = ["en_US"];
                                resourceManager.addEventListener("change", 
xmlbinding);
                        }
                        
                        private function xmlbinding(event:Event):void
                        {
                                
dispatchEvent(ValueChangeEvent.createUpdateEvent(this, "menuDataXMLList", null, 
menuDataXMLList));
                        }
                        
                        [Bindable]public var switchLocale:String = "Switch 
Locale";
                        
                        private function changeLocale():void {
                                var locale:String = 
resourceManager.localeChain[0];
                                if(resourceManager.localeChain[0] != "en_US") {
                                        resourceManager.localeChain = ["en_US"];
                                } else {
                                        resourceManager.localeChain = ["es_ES"];
                                }
   
                                trace(menuDataXMLList.toXMLString());
                                
                        }
                        
                        
                        private function dummyMethod(event:MouseEvent):void {
                        }
                        
                ]]>
        </fx:Script>
        
        <fx:Declarations>
                <fx:XMLList id="menuDataXMLList">
                        <menuitem label="label-1">                      
                                <menuitem label="label-1-1"/>                   
                                <menuitem label="label-1-2"/>                   
                        </menuitem>
                        <menuitem 
label="{resourceManager.getString('containers', 'noColumnsFound')}" id="admin" 
>                      
                                <menuitem label="label-2-1"/>                   
                                <menuitem label="label-2-2"/>                   
                                <menuitem 
label="{resourceManager.getString('containers', 'noRowsFound')}" id="admin" />
                        </menuitem>
                </fx:XMLList>
        </fx:Declarations>      
        
        <s:layout>
                <s:VerticalLayout gap="10" paddingRight="10" paddingLeft="10" 
paddingTop="10" paddingBottom="20" />
        </s:layout>
   
        <s:Button label="{resourceManager.getString('containers', 
'noRowsFound')}" click="changeLocale()"/>
        
        <mx:MenuBar id="menuBar_fx_Declarations" width="100%" 
dataProvider="{menuBarData2}" horizontalCenter="0"
                                itemClick="itemClickHandler(event)" 
                                labelField="@label" 
                                
creationComplete="creationCompleteHandler2(event)"/>    
   </s:Application>
   ```
   
   In the example, I use a custom event listener to listen for the locale 
change and fake an update event on the XMLList, but the way the XMLList is set 
in the MenuBar is much simpler than what I think you are doing.  This example 
was written to prove that the updating source would work, and not to work in 
your usage. So now you should have the option of replacing the 
XMLListCollection or updating the XMLListCollection.source.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to