2 Replies Latest reply on Jan 10, 2011 8:17 AM by whiterrabbit

    communicating between classes

    whiterrabbit

      I have one class calling another class. When the called class is done doing what its supposed to be doing its supposed to dispatch and event but its throwing a type coercion error

       

      Here is the class doing the calling

       

      package classes
      {
           import flash.events.Event;
           import flash.events.EventDispatcher;
           
           import mx.collections.ArrayCollection;
           import mx.rpc.events.ResultEvent;
           
           public class InitJobDetails extends EventDispatcher {
                
                public var HTTPC:HttpQueery; //Takes 3 Parameters - Params, Url Method
                private var _params:Object = new Object();
                public var _opsArr:ArrayCollection;
                
                public function InitJobDetails(event:Event) {
                _params["id"] = event.currentTarget.selectedItem.jobid;
                HTTPC = new HttpQueery(_params,"http://10.16.1.53/viewjobops.php","POST");
                HTTPC.addEventListener("Completed", notifymain);
                }
                
                private function notifymain(event:ResultEvent):void {
                     _opsArr = HTTPC._tempArray;
                     dispatchEvent(new Event("notifyMain"));
                }
      
           }
      }
      
      

       

      and here is the class being called

      package classes
      {
           //Takes 3 Parameters - Params, Url Method
           import flash.events.Event;
           import flash.events.EventDispatcher;
           
           import mx.collections.ArrayCollection;
           import mx.rpc.events.ResultEvent;
           import mx.rpc.http.HTTPService;
           
           public class HttpQueery extends EventDispatcher {
                private var params:Object = new Object();
                private var _url:String;
                private var _method:String;
                public var _tempArray:ArrayCollection;
                public var RPF:ResultProxyFix;
                
                public function HttpQueery(Qparams:Object, Qurl:String, Qmethod:String) {
           
                     params = Qparams;
                     _url = Qurl;
                     _method = Qmethod;
                     
                     var QY:HTTPService = new HTTPService;
                     QY.url = _url;
                     QY.method = _method;
                     QY.addEventListener(ResultEvent.RESULT, completed);
                     QY.send(params);
                     }
           
           
           
                private function completed(event:ResultEvent):void {
                RPF = new ResultProxyFix(event);
                _tempArray = RPF.tempArray;
                dispatchEvent(new Event("Completed"));
                }
           }
      }
      
      

       

       

      The error gets thrown when this class tries to dispatch the event "Completed" otherwise I am getting my data on the http request. Am I doing this wrong?

      Below is the error being thrown

       

      TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@1d369be1 to mx.rpc.events.ResultEvent.

      at flash.events::EventDispatcher/dispatchEventFunction()

      at flash.events::EventDispatcher/dispatchEvent()

      at classes::HttpQueery/completed()[/Users/jorgepease/Documents/Flex Builder 3/ArrowmailJobBoard/src/classes/HttpQueery.as:36]

      at flash.events::EventDispatcher/dispatchEventFunction()

      at flash.events::EventDispatcher/dispatchEvent()

      at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\framewor ks\projects\rpc\src\mx\rpc\AbstractInvoker.as:170]

      at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\ projects\rpc\src\mx\rpc\AbstractInvoker.as:193]

      at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responde r.as:43]

      at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\ AsyncRequest.as:74]

      at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\s rc\mx\messaging\channels\DirectHTTPChannel.as:403]

      at flash.events::EventDispatcher/dispatchEventFunction()

      at flash.events::EventDispatcher/dispatchEvent()

      at flash.net::URLLoader/onComplete()

       

      Thanks for your help