2 Replies Latest reply on Jul 6, 2010 6:03 AM by BhaskerChari

    Videophone example, XML result into a list?


      In the video phone application, the reg.cgi appears to ouput a list of 'friends' in xml format

      (from regcgi)

      for f in friends:
          print "\t<friend>\n\t\t<user>%s</user>" % (xml.sax.saxutils.escape(f), )
          c = db.cursor()
          c.execute("select m_username, m_identity from registrations where m_username = ? and m_updatetime > datetime('now', '-1 hour')", (f, ))
          for result in c.fetchall():
              eachIdent = result[1]
              if not eachIdent:
                  eachIdent = ""
              print "\t\t<identity>%s</identity>" % (xml.sax.saxutils.escape(eachIdent), )
              if f != result[0]:
                  print "\t\t<registered>%s</registered>" % (xml.sax.saxutils.escape(result[0]), )
          print "\t</friend>"


      and the flash app appears to get the results as follows


      (from httpmanager)

      else if (result.result.hasOwnProperty("friend"))
                          // party query response
                          remote = result.result.friend as Object;
                          if (remote.hasOwnProperty("user") && remote.hasOwnProperty("identity"))
                              var identityString:String = remote.identity
                              var userString:String = remote.user;
                              var r:IdManagerEvent = new IdManagerEvent("lookupSuccess", userString, identityString);



      and it places a call to one of the 'friends' as follows


      (from the videophone app file)

      else if (e.type == "lookupSuccess")
                          // party query response
                          var i:IdManagerEvent = e as IdManagerEvent;
                          placeCall(i.user, i.id);   



      My query is, how would I take the full list that was returned as XML, and for example, populate a list with that data?

      How do you iterate through the list, extracting the required values and put them into a list?


      Im new to flash, and trying to get my head around how to do these simple things...


      Can anyone shed any light, as Im learning loads, but keep hitting struggling points like this as I dont have a clue how flash does these things, and dont know what to investigate... Once a pointer in the right direction is given,  a small example like this is shown, I can take it from there, and investigate/learn more.



        • 1. Re: Videophone example, XML result into a list?
          rootsounds Level 4

          Read up on E4X in Flex. It makes short work of XML tasks.

          • 2. Re: Videophone example, XML result into a list?
            BhaskerChari Level 4

            Hi ken_from_uk,


            you can convert your xml to an array collection and you can easily iterate using for loop and access the values in the list ...You can see the code below how to convert xml to ArrayCollection...


            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="convertXMLtoArrayCollection()">
               import mx.collections.ArrayCollection;
               import mx.rpc.xml.SimpleXMLDecoder;
               private var arrayCollection:ArrayCollection = new ArrayCollection();
               private function convertXMLtoArrayCollection():void
                var xml:XML = new XML(xmlStates.toString());
                var xmlDoc:XMLDocument = new XMLDocument(xml);
                var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
                var resultObj:Object = decoder.decodeXML(xmlDoc);
                if(resultObj.states.state is ArrayCollection)
                 arrayCollection = resultObj.states.state as ArrayCollection;
                else if(resultObj.states.state is Object)
            <mx:XML xmlns="" id="xmlStates">
                      <name_state>State x:</name_state>
                              <name_city>City One</name_city>
                              <name_city>City Two</name_city>
                              <name_city>City Three</name_city>
                      <name_state>State y:</name_state>
                              <name_city>City Four</name_city>
                              <name_city>City Five</name_city>
                              <name_city>City Six</name_city>



            Bhasker Chari