flex与后台交互的4种方法

一、HTTPService

程序代码:


http://www.adobe.com/2006/mxml
" layout="absolute" initialize="initializeHandler(event)">

private function initializeHandler(event:Event):void {
countriesService.send();
}
private function changeHandler(event:Event):void {
statesService.send();
}
]]>


http://www.rightactionscript.com/states/xml/countries.xml
" />

http://www.rightactionscript.com/states/xml/states.php
">


{country.value}




change="changeHandler(event)" />



二、URLLoader

程序代码:


http://www.adobe.com/2006/mxml
" layout="absolute" initialize="initializeHandler(event)">

private var _countriesService:URLLoader;
private var _statesService:URLLoader;
private function initializeHandler(event:Event):void {
_countriesService = new URLLoader();
_countriesService.addEventListener(Event.COMPLETE, countriesCompleteHandler);
_countriesService.load(new URLRequest("
http://www.rightactionscript.com/states/xml/countries.xml"));
_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);
}
]]>





三、WebService 方法一

程序代码:


http://www.adobe.com/2006/mxml
" layout="absolute" initialize="initializeHandler(event)">

private function initializeHandler(event:Event):void {
statesService.getCountries();
}
private function changeHandler(event:Event):void {
statesService.getStates(country.value);
}
]]>

wsdl="
http://www.rightactionscript.com/states/webservice/StatesService.php?wsdl">




dataProvider="{statesService.getCountries.lastResult}" change="changeHandler(event)" />


四、WebService 方法二

程序代码:


http://www.adobe.com/2006/mxml
" layout="absolute" initialize="initializeHandler(event)">

private function initializeHandler(event:Event):void {
statesService.getCountries.send( );
}
private function changeHandler(event:Event):void {
statesService.getStates.send( );
}
]]>

http://www.rightactionscript.com/states/webservice/StatesService.php?wsdl
">



{country.value}




dataProvider="{statesService.getCountries.lastResult}" change="changeHandler(event)" />


你可能感兴趣的:(flex)