0 Replies Latest reply on Oct 5, 2010 10:42 AM by jer.bradley

    MenuBar with XMList dp -- woes migrating to Flex4

    jer.bradley

      I'm migrating an application from flex 3 to flex 4, and I have a menubar which is populated with an xmllist

       

      I'm using unique xml nodes for menu items to easily manipulate the state of the menu (primarily setting the enabled property). In Flex 3, this worked like a charm -- in Flex 4 it's a disaster. After some debugging with namespace issues, I'm able to "query" the xmllist again with E4X dot notation, but I'm unable to set attributes in the XMLlist anymore (particuarly the enabled property).

       

      Flex4 XMLLists appear to apply a namespace to all XML (specifically the 2009 namespace) which I figured out I had to use that namespace to work with the XML using E4X.

       

      The compoment definition is:

       

      <?xml version="1.0" ?>
      <mx:Canvas xmlns="http://ns.adobe.com/mxml/2009"
                 xmlns:s="library://ns.adobe.com/flex/spark"
                 xmlns:mx="library://ns.adobe.com/flex/mx"
                 creationComplete="init()">

       

      The XMLList (or rather an exerpt) is defined as:

       

      <Declarations>

      <XMLList id="myMenu">
                  <features label="Feature">
                      <newFocusArea label="New Focus Area" action="createFeature" data="Focus Area Draft"
                                    geomType="{Draw.POLYGON}" icon="newIcon"/>
                      <newMechanism label="New Mechanism" action="createFeature" data="Mechanism"
                                    geomType="{Draw.POLYGON}" icon="newIcon"/>
                      <newProject label="New Project" action="createFeature" data="Project"
                                  geomType="{Draw.POLYGON}" icon="newIcon"/>
                      <newAccomp label="New Accomplishment">
                          <newAccompPoint label="Point" action="createFeature" data="Accomplishment Point"
                                          geomType="{Draw.MAPPOINT}" icon="newIcon"/>
                          <newAccompLine label="Line" action="createFeature" data="Accomplishment Line"
                                         geomType="{Draw.POLYLINE}" icon="newIcon"/>
                          <newAccompArea label="Area" action="createFeature" data="Accomplishment Area"
                                         geomType="{Draw.POLYGON}" icon="newIcon"/>
                      </newAccomp>

       

                      <menuitem type="separator"/>

       

                      <editFeature label="Edit" action="{DrawManager.EDIT}" enabled="false" icon="editIcon"/>
                      <saveFeature label="Save" action="{DrawManager.SAVE}" enabled="false" icon="saveIcon"/>
                      <revert label="Revert Changes" action="{DrawManager.REVERT}" enabled="false" icon="revertIcon"/>
                      <deleteFeature label="Delete" action="{DrawManager.DELETE}" enabled="false" icon="deleteIcon"/>

       

                      <menuitem type="separator"/>

       

                      <setWorkingMech label="Set Active Mechanism" action="setWorkingMech" data="mech"
                                      enabled="false" icon="activeIcon"/>
                      <setWorkingProj label="Set Active Project" action="setWorkingProj" data="proj"
                                      enabled="false" icon="activeIcon"/>

       

                      <menuitem type="separator"/>

       

                      <attribs label="Edit Properties..." action="LOAD_FORM_SELECTED" enabled="false"
                               icon="editPropsIcon"/>
                      <attachFiles label="Attach Files..." action="files" enabled="false" icon="attachIcon"/>

      ...

      </XMLList>

      </Declarations>

       

      and the MenuBar:

       

      <mx:MenuBar alpha=".25" id="mainMenu" labelField="@label" iconField="@icon" itemClick="menuHandler(event)"
                              focusAlpha=".8" dataProvider="{myMenu}"/>

       

      Using the above, I can get the xml nodes correctly if I use the correct namespace, but attempted manipulation such as the below fails to update the menu (options aren't being disabled):

       

      namespace ns = "http://ns.adobe.com/mxml/2009"

      use namespace ns;

      myMenu.newFocusArea.@enabled = false;

       

      or

       

      myMenu.*::newFocusArea.@enabled = false;

       

      Any help getting this state manipulation to work in Flex4 would be appreciated.