user2104391
user2104391

Reputation: 413

Adobe Flex Action Script - Response Object

I have the Adobe Flex Application, from the cgi script, i receive response Object as XML

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, httpResult);

loader.load(request);

private function httpResult(e:Event):void
{   
    Alert.show("XML: " + new XML(e.target.data));
    var result:XML = XML(e.target.data) as XML;
    Alert.show("hasOwnProperty(result): " + result.hasOwnProperty("result"));
}

Below is my Response Object at Alert "XML: "

<result>
    <update>insert</update>
</result>

But the Alert "hasOwnProperty(result): " shows "False"

Upvotes: 1

Views: 312

Answers (1)

NemoStein
NemoStein

Reputation: 2098

<result> is the root element of your XML.
Try the following:

private function httpResult(e:Event):void
{   
    var result:XML = XML(e.target.data);
    Alert.show("has update property: " + result.hasOwnProperty("update"));
}

Edit: To make it clear, take a look at the following code:

var xml:XML = XML("<result><update>insert</update></result>");

trace("XML:", xml);
trace("result:", xml.hasOwnProperty("result"));
trace("update:", xml.hasOwnProperty("update"));

The output in the console will be like this:

XML: <result>
  <update>insert</update>
</result>
result: false
update: true

Upvotes: 2

Related Questions