2 Replies Latest reply on Jun 29, 2006 8:20 AM by ur_dtrain

    Get data from event handler

    doug777 Level 1
      The correct data is in the event handler, but presumably gets set after myFunc ends.

      How can I get the data out of the event handler?

      My code:

      package mypackage{
      import mx.rpc.events.*;
      import mx.rpc.remoting.RemoteObject;
      import mx.managers.CursorManager;
      import mx.utils.ObjectUtil;
      import mx.controls.Alert;

      public class MyClass{

      public var mydata:Object = {};

      public function myFunc():void{
      var svc:RemoteObject = new RemoteObject();
      svc.destination = "ColdFusion";
      svc.source = "myDir.myCFC";
      svc.myMethod.addEventListener("result", resultHandler);
      svc.addEventListener("fault", faultHandler);
      Alert.show( ObjectUtil.toString(mydata) );//shows null object

      private function resultHandler(event:ResultEvent):void{
      this.mydata = event.result;
      Alert.show( ObjectUtil.toString(mydata) );//shows correct returned data
      private function faultHandler(event:FaultEvent):void{
      Alert.show( ObjectUtil.toString(event.fault) );