Kenwio
08-20-2008, 12:46 PM
Hi!
I want to dispatch an event from the MODEL(Stations) to the VIEW, when the Stations.onResult() function has been executed.
How do I do this??
This is the MODEL:
package classes.model {
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import XMLList;
import mx.collections.XMLListCollection;
import flash.system.Security;
public class Stations {
private var _httpService:HTTPService = new HTTPService();
private var _xmlData:XMLList = new XMLList();
[Bindable]
private var _xmlDataCollection:XMLListCollection;
public function Stations():void {
_httpService.url = "http://localhost/te.php";
_httpService.useProxy = false;
_httpService.method = "POST";
_httpService.resultFormat = "e4x";
_httpService.addEventListener(ResultEvent.RESULT, onResult)
_httpService.send();
}
public function onResult(event:ResultEvent):void {
_xmlData = event.result.fields.field;
_xmlDataCollection = new XMLListCollection(_xmlData);
}
public function getTheData():XMLListCollection {
return _xmlDataCollection;
}
}
}
This is the VIEW:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()">
<mx:Script>
<![CDATA[
import classes.model.Stations;
import mx.collections.XMLListCollection;
[Bindable]
private var stationData:Stations = new Stations();
private function init():void {
trace (stationData.getTheData());
}
]]>
</mx:Script>
<mx:VBox>
<mx:DataGrid id="stationGrid" dataProvider="{stationData.getTheData()}" />
</mx:VBox>
</mx:Panel>
Please help!
I want to dispatch an event from the MODEL(Stations) to the VIEW, when the Stations.onResult() function has been executed.
How do I do this??
This is the MODEL:
package classes.model {
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import XMLList;
import mx.collections.XMLListCollection;
import flash.system.Security;
public class Stations {
private var _httpService:HTTPService = new HTTPService();
private var _xmlData:XMLList = new XMLList();
[Bindable]
private var _xmlDataCollection:XMLListCollection;
public function Stations():void {
_httpService.url = "http://localhost/te.php";
_httpService.useProxy = false;
_httpService.method = "POST";
_httpService.resultFormat = "e4x";
_httpService.addEventListener(ResultEvent.RESULT, onResult)
_httpService.send();
}
public function onResult(event:ResultEvent):void {
_xmlData = event.result.fields.field;
_xmlDataCollection = new XMLListCollection(_xmlData);
}
public function getTheData():XMLListCollection {
return _xmlDataCollection;
}
}
}
This is the VIEW:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()">
<mx:Script>
<![CDATA[
import classes.model.Stations;
import mx.collections.XMLListCollection;
[Bindable]
private var stationData:Stations = new Stations();
private function init():void {
trace (stationData.getTheData());
}
]]>
</mx:Script>
<mx:VBox>
<mx:DataGrid id="stationGrid" dataProvider="{stationData.getTheData()}" />
</mx:VBox>
</mx:Panel>
Please help!