2 Replies Latest reply on May 15, 2007 2:12 PM by M40

    Event Dispatch

      I have this simple Flex / ActionScript function that sends data to a PHP file. Then the PHP file parses the received data and returns another data to the Flex function. What I'd love to know is how to make this simple function dispatch a simple event when it complete loading data from the PHP file.

      The function looks like that:

      public static function myFunction(postData:String):void {

      var _URLRequest:URLRequest = new URLRequest()

      _URLRequest.url = "http: //www.site.com/file.php";
      _URLRequest.data = "data="+postData;
      _URLRequest.method = URLRequestMethod.POST;

      var _URLLoader:URLLoader = new URLLoader(_URLRequest);

      _URLLoader.addEventListener("complete", dispatchCompleteEvent);


      I hope you could help me with some idea!

      Thank you very much!
        • 1. Re: Event Dispatch
          ashar2005 Level 1
          Use an RPC call so you can send and get data, use an <mx:HTTPService>
          tag with a result="resultHandler(event)" so the results can be handled
          and you can send your dispatchEvent. Example below....

          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" >

          import mx.rpc.events.ResultEvent;
          import mx.rpc.http.HTTPService;

          public function sendData(postData:String):void {

          var s:Object = new Object();
          s.data = postData;

          private function resultHandler(event:ResultEvent):void

          var myResults:Object = event.result;
          var o:Event = new Event("gotMyResults");



          <mx:HTTPService id="myHTTPService"
          url=" http://www.site.com/file.php"

          • 2. Re: Event Dispatch
            M40 Level 1
            Thank you for your comment ashar2005!

            Though that seems not to be what I'm looking for. I actually can send and get data with the function I wrote. I can access the loaded data from the URLLoader object. Using URLLoader I can also use "complete" event, dispatched when the data is loaded.

            The thing is I need the function to dispatch its own event when the data is loaded by the URLLoader object.

            Now I realize that I had to create this topic in the ActionScript section so I'm sorry about that.