1 Reply Latest reply on Sep 19, 2007 5:48 AM by zorglub76

    mx:XML vs mx:HTTPService

    wy790289
      Hi,

      I have an application that there is a user menu will be displayed when user login to the program and the program will build the menu (using menu bar or tree object) by retrieve the access rights to the application. Since the program will dynamically building the menu, I will calling a HTTPService and return a XML of menu structure. When I test the program, I will first create a static XML file representing a hierarchical structure menu and calling the HTTPService to get the content. After the HTTPService call and result returned. The menu only show the "top level" menu item on both menubar and tree object. I also try to create a mx:XML object which retrieve the same XML file, both menubar and tree object showing the menu are correct.

      Can I use the HTTPService to return a XML which is equal to a XML object defined in the application? I will prefer to use HTTPService because I can storing the menu structure of each user into database table to retrieve and create different menu for every user.

      I create the objects as follow:
      <mx:HTTPService id="mainMenux" url="mainmenu.xml" />
      <mx:XML format="e4x" id="mainMenu" source="mainmenu.xml"/>

      The menu will show correctly for below settings (using mx:XML as data provider):
      <mx:Tree x="10" y="10" width="250" top="10" bottom="10" dataProvider="{mainMenu.menuitem}" labelField="@label" showRoot="true" id="tree1" enabled="false"></mx:Tree>

      <mx:MenuBar left="5" right="5" top="0" id="myMenu" dataProvider="{mainMenu.menuitem}" labelField="@label" fontSize="12" enabled="false"></mx:MenuBar>

      When I use HTTPService as data provider, it only show top level items:
      <mx:MenuBar left="5" right="5" top="0" id="myMenux" dataProvider="{mainMenu.lastResult.root.menuitem}" labelField="label" fontSize="12" enabled="false"></mx:MenuBar>

      The XML file "mainmenu.xml":
      <?xml version="1.0" encoding="utf-8" ?>
      <root>
      <menuitem label="系統工具">
      <menuitem label="關閉本頁" act="closeCurrentTab" />
      </menuitem>

      <menuitem label="網上表格">
      <menuitem label="電腦帳戶要求" act="addUserRequest"/>
      </menuitem>

      <menuitem label="地址簿">
      <menuitem label="資料維護">
      <menuitem label="地址簿" />
      <menuitem label="聯絡資料" />
      <menuitem label="A/R資料" />
      <menuitem label="A/P資料" />
      </menuitem>
      <menuitem label="查詢">
      </menuitem>
      <menuitem label="報表">
      <menuitem label="客戶資料表" />
      <menuitem label="標籤列印" />
      </menuitem>
      </menuitem>

      <menuitem label="銷售">
      </menuitem>

      <menuitem label="採購">
      </menuitem>

      <menuitem label="庫存">
      </menuitem>

      <menuitem label="財務">
      </menuitem>
      </root>

      Please ignore the value of "label" tag because those are in Chinese

      Thanks a lot!
        • 1. mx:XML vs mx:HTTPService
          zorglub76
          I'm pretty new to Flex, but maybe the answer for your question lies in "resultFormat" property of the HTTPService object. By default, resultFormat is "object", so HTTPService returns results in form of object. Try using resultFormat="e4x". It should help....