URLLoader交互的例子
[color=red][size=large]分析:[/size][/color]
[color=green]changeHandler方法里的请求URL,可以进行设计,可以在URL中添加变量、参数。使用ComboBox来控制发送参数或者请求的URL地址,同样也可以,使用TextInput或者TextField来决定请求或交互的参数。[/color]
<?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]