views:

344

answers:

1

Hi guys, I am using Flex and with the AS3 libraries. I can make calls etc but when i get values returned in the event, they are in RawResult. I am not sure how to turn that into an arraycollection etc so i can make use of it in flex, or if there is a better way of accessing the data, generally speaking.

tried=

var friendsDoc : XMLDocument = new XMLDocument(e.data.rawResult);
              var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
                    var resultObj:Object = decoder.decodeXML(friendsDoc);
        //var testString: String = resultObj.user[0].uuid as String;      
        nameText.text = resultObj.user[0].uuid as String;
+1  A: 

Is the rawResult a valid xml string? Then you can use e4x in AS3. The XML class from AS2 is retained in AS3 as XMLDocument class for backward compatibility. It is recommended to use the e4x enabled XML class in AS3.

Using the e4x syntax, your code can be simplified to a couple of lines.

Let's say rawResult was

<root xmlns="http://some.url"&gt;
  <user id="1">
    <uuid>something</uuid>
  </user>
  <user id="2">
    <uuid>something else</uuid>
  </user>
</root>

We can parse it like:

var friendsDoc:XML = new XML(e.data.rawResult);
var ns:Namespace = new Namespace("http://some.url");
trace(friendsDoc.ns::user[0].ns::uuid);//something
trace(friendsDoc.ns::user[1].ns::@id);//2
trace(friendsDoc.ns::user.(@id == "2").ns::uuid);//something else
Amarghosh
The thing is the rawResult is like <fql_query_response list="true" xmlns="..."> <friend_info> <uid2> 1303529</uid2></friend_info><friend_info><uid2>1303522</uid2></friend_info>. When i try what you say, i get 'A term is undefined and has no properties'.
Doron Katz
Thats because of namespaces. Updated the code to fix it.
Amarghosh
hey mate i tried that and still get the term error, and its pointing to the trace line as the line of error.
Doron Katz
Is there another way besides using xml to get the friends list, ie through an arraycollection or something, or does it have to be parsed?
Doron Katz
Does any other tag than the root (like friend_info or uid) have xmlns declarations? If so, you have to call them with their respective namespaces. See the link in my post http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=4#e4x for more info on xml namespaces
Amarghosh
Since the data is an xml string, you have to parse it using xml itself. no other way.
Amarghosh