Add loading complete event for 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>
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://localhost/countries.xml"));
}
private function countriesCompleteHandler(event:Event):void {
var xml:XML = new XML(_countriesService.data);
country.dataProvider = xml.children();
}
private function changeHandler(event:Event):void {
var request:URLRequest = new URLRequest("http://localhost/state.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:VBox>
</mx:Application>
Related examples in the same category