9 Replies Latest reply on Jan 11, 2010 11:37 AM by ACFlex

    Easy Question: XML in Flex

    lkenney2

      I'm creating the UI for a player that has to be easily customizable. The position of the button is based on the type of client using the player, so I have an xml document that looks like this:

       

      <?xml version="1.0"?>
      <buttonpositions>
          <button position='btnPos1'>
              <x>10</x>
              <y>10</y>
          </button>
      </buttonpositions>

       

      I then load the data from the xml file into the Flex .mxml file. I'm pretty sure the xml document is loaded correctly, and there are no problems with the build or at runtime, so why won't the buttons move to thwir places?

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" width="768"
                      initialize="init();">
         
          <fx:Script>
              <![CDATA[
                  import flash.net.URLLoader;
                  import flash.net.URLRequest;
                  import flash.xml.*;
                 
                  [Bindable]
                  private var xmlLoader:URLLoader = new URLLoader();
                  [Bindable]
                  private var xmlData:XML = new XML();
                 
                  private function init():void{
                      xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
                      xmlLoader.load(new URLRequest("unitConfig.xml"));
                  }
                 
                  private function LoadXML(e:Event):void {
                      xmlData = new XML(e.target.data);
                  }

       

              ]]>
          </fx:Script>
         
          <mx:TabNavigator width="600" height="400" id="tabNav">

       

              <s:NavigatorContent label="Listen &amp; Repeat" width="100%" height="100%" id="tbListenandRepeat">
                  <mx:Button id="btnLRRec" x="{xmlData.button[0].x}" y="{xmlData.button[0].y}" styleName="StoryRecord" enabled="true"/>
                  <mx:Button id="btnLRSkip" x="{xmlData.button[1].x}" y="{xmlData.button[1].y}" styleName="Skip" enabled="true"/>
              </s:NavigatorContent>
             
          </mx:TabNavigator>

       

         
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>   
         
      </mx:Application>