Flex的通信方式(N)——URLLoader

URLLoader交互的例子


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
initialize="initializeHandler(event)">
<mx:Script>
<![CDATA[
import flash.net.*;
// flash.net.URLLoader
private var _countriesService:URLLoader;
private var _statesService:URLLoader;

private function initializeHandler(event:Event):void
{
_countriesService = new URLLoader();
_countriesService.addEventListener(Event.COMPLETE, countriesCompleteHandler);
var request:URLRequest = new URLRequest("http://www.rightactionscript.com/states/xml/countries.xml");
_countriesService.load(request);
_statesService=new URLLoader();
_statesService.addEventListener(Event.COMPLETE, statesCompleteHandler);
XML.ignoreWhitespace=true;
}

private function countriesCompleteHandler(event:Event):void
{
var xml:XML=new XML(_countriesService.data);
country.dataProvider=xml.children();
}

private function statesCompleteHandler(event:Event):void
{
var xml:XML=new XML(_statesService.data);
state.dataProvider=xml.children();
}

private function changeHandler(event:Event):void
{
var request:URLRequest=new URLRequest("http://www.rightactionscript.com/states/xml/states.php");
var parameters:URLVariables=new URLVariables();
parameters.country=country.value;
request.data=parameters;
_statesService.load(request);
}
]]>
</mx:Script>
<mx:VBox>
<mx:ComboBox id="country"
change="changeHandler(event)"/>
<mx:ComboBox id="state"/>
</mx:VBox>
</mx:Application>




[color=red][size=large]分析:[/size][/color]
[color=green]changeHandler方法里的请求URL,可以进行设计,可以在URL中添加变量、参数。使用ComboBox来控制发送参数或者请求的URL地址,同样也可以,使用TextInput或者TextField来决定请求或交互的参数。[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值