1.新建 Mxml 应用程序 2.编写如下代码 2.1首先创建HTTPService对象并设置相关属性 2.2利用初始化完成函数执行HTTPServer的send()方法发送请求 2.3实现回调函数 3.运行测试
<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009" creationComplete="application1_creationCompleteHandler()" 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.rpc.events.ResultEvent; import mx.controls.Text; import mx.events.FlexEvent; PRotected function http_resultHandler(event:ResultEvent):void { var result:String = event.result as String; textarea.text=result; } protected function application1_creationCompleteHandler():void { http.send(); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <s:HTTPService id="http" url="http://www.baidu.com/" resultFormat="text" result="http_resultHandler(event)" /> </fx:Declarations> <s:TextArea id="textarea" x="184" y="58" width="444"/></s:Application>新闻热点
疑难解答