4 Replies Latest reply on Jun 28, 2010 12:51 PM by jerry98225

    event.COMPLETE handler question....

    jerry98225 Level 1

      Hi guys.

         I want to dispatch a custom event when the two files are downloaded or uploaded successfully. I use

       

       

      fileRef.addEventListener(Event.COMPLETE, completeHandler);

      fileBigRef.addEventListener(Event.COMPLETE, completeHandler);

       

       

      to listen the complete event with only 1 handler.

       

      function completeHandler(event:Event):void{

         fileBigRef.removeEventListener(Event.COMPLETE,completeHandler);

         fileRef.removeEventListener(Event.COMPLETE,completeHandler);

       

          var e:Event=new Event("addInfoDone");

          dispatchEvent(e);

       

      }

       

      I want the event to be dispatched only once when both of the fileRef and fileBigRef are complete transfered. Any ideas?? My brain is fry now and can't think of anything.....  Thanks for the help.

        • 1. Re: event.COMPLETE handler question....
          VRPDeveloper Level 3

          You need to create 2 boolean variables for fileRef and  fileBigRef and by default they are false but as soon as file is uploaded or downloaded make it true.

           

          You can do something like this...

           

          var fileRefbol:Boolean =false;

          var  fileBigRefbol :Boolean =false;

           

           

          function completeHandler(event:Event):void{

            if(event.currentTarget==fileRef){

               fileRefbol=true;

          }

          if(event.currentTarget== fileBigRef ){

                fileBigRefbol =true;

          }

          if( fileBigRef && fileRefbol){

              var e:Event=new Event("addInfoDone");

              dispatchEvent(e);

          }

          }

           

          Hope you got my point!!

          1 person found this helpful
          • 2. Re: event.COMPLETE handler question....
            jerry98225 Level 1

            Thanks a lot VRP. However, when I try to use the debug mode, the currentTarget is the object FileReference.

            Even if I go for event.currentTarget.name, it will refer to the image name....

            It won't be fileRef. so basically, the fileRefbol will never be true...I am not sure if I miss something...

             

             

            function completeHandler(event:Event):void{

              if(event.currentTarget==fileRef){  //currentTarget is the object FileReference

                 fileRefbol=true;

            }

            • 3. Re: event.COMPLETE handler question....
              VRPDeveloper Level 3

              You can do in other way then

               

               

              var fileRefbol:Boolean =false;

              var  fileBigRefbol :Boolean =false;

               

               

              function completeHandler(event:Event):void{

                if(FileReference(event.currentTarget).id==fileRef){

                   fileRefbol=true;

              }

              if(FileReference(event.currentTarget).id== fileBigRef ){

                    fileBigRefbol =true;

              }

              if( fileBigRef && fileRefbol){

                  var e:Event=new Event("addInfoDone");

                  dispatchEvent(e);

              }

              }

               

               

              I think it will work now....

              • 4. Re: event.COMPLETE handler question....
                jerry98225 Level 1

                nice! Thanks a lot!