flex 调用XML数据

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" creationComplete="creationCompleteHandler(event)"
  xmlns:s="library://ns.adobe.com/flex/spark"
  xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
    import mx.events.FlexEvent;
    import mx.rpc.events.ResultEvent;
   
    protected function creationCompleteHandler(event:FlexEvent):void
    {
        trace(fx_xml);//请求本地XML数据
        http_xml.send();//发送xml请求
    }
   
    protected function http_xml_resultHandler(event:ResultEvent):void
    {
        var myxml:XML = event.result as XML;
        trace(myxml);
    }
   
    ]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<!--第一种方式-->
<fx:XML xmlns="xml" id="fx_xml" source="xml/data.xml" format="e4x" />

<!--第二种方式 -->
<s:HTTPService id="http_xml" url="xml/data.xml" resultFormat="e4x" result="http_xml_resultHandler(event)" />
</fx:Declarations>
</s:Application>

你可能感兴趣的:(Flex)