Flex与后台交互的4种方法
一、HTTPService 程序代码:
private function initializeHandler(event:Event):void {
countriesService.send();
}
private function changeHandler(event:Event):void {
statesService.send();
}
]]-->
{country.value}
控件接收的内容提供,并且由这个ComboBox控制着第二个ComboBox所要显示的内容 -->
二、URLLoader
程序代码:
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 方法一 程序代码:
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 方法二
程序代码:
private function initializeHandler(event:Event):void {
statesService.getCountries.send( );
}
private function changeHandler(event:Event):void {
statesService.getStates.send( );
}
]]-->
{country.value}
dataProvider="{statesService.getCountries.lastResult}" change="changeHandler(event)" />