开发者

Flex/PHP/XML data issue

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
            protec开发者_运维技巧ted 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>


Try "@id" instead of "id".


All sorted...

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜