0 Replies Latest reply on Jun 8, 2009 12:27 AM by j-tin

    Reg. event dispatching in AS2

    j-tin

      Hi there,

       

      I have created a simple class called Question which gets data from database using Remoting. I have created an instance of this class in another AS file. Now whenever data comes from server, one event gets dispatched. Now my problem is htat i am not able to trace it using the Question class instance.

       

      Below is the snapshot of the code i am taking about.

       

       

      class Question
      {
      private var QuestionNums:Number;
      private var rConnect:RemotingConnector;
      private var QuestionObjArr:Array = new Array();

      public var dispatchEvent:Function;
      public var addEventListener:Function;
      public var removeEventListener:Function;

       

      public var tmpVar;
      public function Question(numOfQues:Number)
      {
        tmpVar = this;
        QuestionNums = numOfQues;
       
        EventDispatcher.initialize(this);

        this.addEventListener("done", completeHandler);
       
        //GetQuestionsFromServer(QuestionNums);

        rConnect = new RemotingConnector();
        //send number of question that need to fetch from server
        rConnect.gatewayUrl =  "http://someDomain/amfphp/gateway.php";
        rConnect.service = "Question.Question";
        rConnect.method = "getQuestionsfromDB";
        rConnect.params = new Array(""+QuestionNums+"");
        rConnect.trigger();
       

        //this is the event which gets fired on data receiving from sever
        rConnect.onResult = function(obj)
        {
         var lObj = new Object();
         QuestionObjArr = new Array();
         for(var a=0; a<obj.length;a++)
         {
         
          lObj.questionTxt = obj[a].questionTxt;
          lObj.opt1 = obj[a].option1;
          lObj.opt2 = obj[a].option2;
          lObj.opt3 = obj[a].option3;
          lObj.opt4 = obj[a].option4;
          lObj.corrAns = obj[a].correctAns;
         
          QuestionObjArr.push(lObj);
         }
         QuestionArrCreated = true;
         dispatchEvent({target:tmpVar,type:"done"})

       

         //*    AT THIS POINT OF TIME I WANT TO FIRE SOME EVENT SO THAT THE INSTANCE OF THIS CLASS CAN DO FURTHER PROCESSING*//

       

       

      Pls. help. My life got stuck here ...
        }
      }