2 Replies Latest reply on Oct 12, 2009 3:30 PM by IptamenosOllandos

    pass xml data to a label using XMLList

    IptamenosOllandos

      Hi,  i read the data from an xml file and trying to pass the contents of one (only the first for example) element to a label:

       <?xml version="1.0" encoding="utf-8"?>
       <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
      creationComplete="questionsData.send()">
       <mx:HTTPService id="questionsData" url="assets/questions.xml" result="questionsHandler(event)" 
      resultFormat="e4x"/>
       <mx:Script>
       <![CDATA[
       import mx.controls.Alert;
       import mx.rpc.events.ResultEvent;
       import mx.collections.ArrayCollection;
       [Bindable]
       public var questionsStock:XMLList;
       public function questionsHandler(evt:ResultEvent):void { 
      questionsStock=evt.result..title; }
       ]]>
       </mx:Script>
       <mx:Label x="210" y="113" text="{questionsStock.text()}" width="216" height="20" id="label1"/> 
      </mx:Application> 
      

      the xml file is like this:

      <?xml version="1.0" encoding="iso-8859-1"?>
       <questions> 
      <question>
       <title>An angle of 45 degrees is in radians:</title>
       <correctAnswer>3</correctAnswer>
       </question>
       <question>
       <title>Which angle is of the same terminal side with an angle of 60 degrees:</title>
       <correctAnswer>2</correctAnswer> 
      </question>
       </questions>
      

      how can i get the content of one title at a time?? with questionsStock.text() i get the content of all titles.

        • 1. Re: pass xml data to a label using XMLList
          UbuntuPenguin Level 4

          Do something like this , assuming you have more than one "question" node and you wouldn't mind storing them in a list of some sort.  Please mark this question as helpful if it is.

           

          public var titleList:ArrayCollection = new ArrayCollection();

           

          public function questionsTitleHandler(evt:ResultEvent):void

          {   

               var resultXML:XML = event.result as XML;
               var titleString:String;

           

               for each(var title:XML in resultXML..question)

               {

                    titleString = resultXML.title;

                    titleList.addItem(titleList);

               }

          }

          • 2. Re: pass xml data to a label using XMLList
            IptamenosOllandos Level 1

            and how can i take my data from titleList to put them to my

            label??titleList[0],

            for example, doesn't work..

             

            2009/10/12 UbuntuPenguin <forums@adobe.com>

             

            Do something like this , assuming you have more than one "question" node

            and you wouldn't mind storing them in a list of some sort.  Please mark this

            question as helpful if it is.

            >

            public var titleList:ArrayCollection = new ArrayCollection();

            >

            public function questionsTitleHandler(evt:ResultEvent):void

            {

                 var resultXML:XML = event.result as XML;

                 var titleString:String;

            >

                 for each(var title:XML in resultXML..question)

                 {

                      titleString = resultXML.title;

                      titleList.addItem(titleList);

                 }

            }

            >

            >