AS3-Facebook: How do I capture the RawResult for calls like for friends
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); 开发者_Go百科 //var testString: String = resultObj.user[0].uuid as String; nameText.text = resultObj.user[0].uuid as String;
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">
<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
精彩评论