tags:

views:

31

answers:

2

I've created a simple Flex application to fetch an XML file. I need a Flex variable "id" to grab the "letters" value from the tag in the XML code, then show the id in an Alert window. When I run this code now (with the full code), the Alert box is blank.

When I run the application in Flex Debug mode, this is what Flex sees: http://static.readescdn.com/misc/flex.gif

Below is the Flex and XML code (edited to only show what's not working):

// Flex
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication ...
    creationComplete="windowedapplication1_creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            // Send the HTTP request
            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                xmlService.send();
            }

            // Receive the HTTP response
            protected function xmlService_resultHandler(event:ResultEvent):void
            {
                // Grab the id
                var id:String = xmlService.lastResult.data.id;

                // Show an alert with the id
                Alert.show(id);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:HTTPService id="xmlService"
                       url="http://localhost/file.xml"
                       method="GET"
                       useProxy="false"
                       resultFormat="e4x"
                       result="xmlService_resultHandler(event)"/>
    </fx:Declarations>
</s:WindowedApplication>

// XML
<?xml version="1.0"?>
<data>
  <id>letters</id>
  <letter label="Letter A">a</letter>
  <letter label="Letter B">b</letter>
  <letter label="Letter C">c</letter>
</data>
A: 

Try "@id" instead of "id".

James Ward
That resulted in an error in Flash Builder:"1084: Syntax error: expecting identifier before atsign"Line: "var @id:String = xmlService.lastResult.data.id;"Any ideas?
Reado
A: 

All sorted...

var data:XML   =  event.result as XML;
var id:String  =  data.id;
Reado