`

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>




分析:
changeHandler方法里的请求URL,可以进行设计,可以在URL中添加变量、参数。使用ComboBox来控制发送参数或者请求的URL地址,同样也可以,使用TextInput或者TextField来决定请求或交互的参数。


分享到:
评论
1 楼 zht110227 2010-07-27  
代码能加上点注释吗?看着效果更好。

相关推荐

Global site tag (gtag.js) - Google Analytics