0 Replies Latest reply on Apr 19, 2007 12:55 PM by thedex1

    using XML

    thedex1 Level 1
      Hi, I am trying to use external XML file to display images and text. I use XML object to hold my XML data. But I don't know how to bind it with mx tags:
      Here is the XML file:
      <Slides>
      <slide id="1">
      <image>images/womanInExer.jpeg</image>
      <headingText>Exercise for Beginners</headingText>
      <descText>Learn how to get started on your exercise program from your Health.com</descText>
      </slide>
      <slide id="2">
      <image>images/magnifyingMan.jpeg</image>
      <headingText>Think again</headingText>
      <descText>about your Health and Fitness</descText>
      </slide>
      <Slides>

      Here is the Application:
      <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="680" height="300" creationComplete="getXMLData()" currentState="slide2">
      <mx:Script>
      <![CDATA[
      private function xmlDataHandler(event:Event):void
      {
      var loader:URLLoader = event.target as URLLoader;
      myXML = new XML(loader.data);
      var arr:ArrayCollection = new ArrayCollection(loader.data);
      imageData = arr.event.Slides.slide.image;
      }

      private function getXMLData():void
      {
      var loader:URLLoader = new URLLoader();
      var request:URLRequest = new URLRequest("headerAnimData.xml");
      loader.load(request);
      loader.addEventListener(Event.COMPLETE, xmlDataHandler);
      }
      </mx:Script>
      ]]>

      <mx:states>
      <mx:State name="slide2" id="a">
      <mx:SetProperty target="{headerImage}" id="aImage" name="source" value="{myXML.slide[1].image}" />
      <mx:SetProperty target="{headingText}" name="text" value="Think again" />
      <mx:SetProperty target="{descText}" name="text" value="about Your Health and Fitness" />
      </mx:State>
      <mx:State name="slide3" id="b">
      <mx:SetProperty target="{headerImage}" name="source" value="images/oranges.jpg" />
      <mx:SetProperty target="{headingText}" name="text" value="Eat Healthy" />
      <mx:SetProperty target="{descText}" name="text" value="Good nutrition and a balanced diet will help you and your child grow up healthy." />
      </mx:State>
      <mx:State name="slide4" id="c">
      <mx:SetProperty target="{headerImage}" name="source" value="images/womanWithGlasses.jpg" />
      <mx:SetProperty target="{headingText}" name="text" value="Be Happy" />
      <mx:SetProperty target="{descText}" name="text" value="Be happy and try to make other people happy as well" />
      </mx:State>
      </mx:states>

      This is not the complete code. I just want to set value of properties using XML data.
      headerImage is an <mx:Image ...>
      headingText is an <mx:Text..>
      descText is an <mx:Text...>

      Any help or suggestion will be greatly appretited.

      Thanks,

      Regards,
      Wahab