2 Replies Latest reply on Aug 12, 2009 6:38 AM by Piotr Wierzgała

    waiting for the end of effect

    Piotr Wierzgała Level 1

      In my Flex application I have a function that plays animation hiding web content and when the animation reaches its end event listener fires another function that change web content and plays second animation which shows new web content. Here is the code:

       

      public function function1(contentId:String):void {
           contentHideAnimation.addEventListener(EffectEvent.EFFECT_END,function2);
           contentHideAnimation.play();
           contentId = id;
      } 
                  
      private function function2(event:Event):void {
           var id:String = contentId;
           moduleLoader.unloadModule();
           if (id == "content1") { moduleLoader.loadModule("modules/content1.swf"); } 
           else if (id == "content2") {moduleLoader.loadModule("modules/content2.swf"); }
           else if (id == "content2") { moduleLoader.loadModule("modules/content3.swf"); }
           contentShowAnimation.play();
      }  
      

       

      What I want to do is to put all the code from both functions in one function (I had to split it into two because move effects (show and hide animations) were played simultaneously).My question is: how can I wait for animation to finish and then play second animation in one function body?

        • 1. Re: waiting for the end of effect
          Madhav Subedi Level 4
          public function function1(contentId:String):void {
               contentHideAnimation.addEventListener(EffectEvent.EFFECT_END,function():void{
                         var id:String = contentId;
                         moduleLoader.unloadModule();
                         if (id == "content1") { moduleLoader.loadModule("modules/content1.swf"); } 
                         else if (id == "content2") {moduleLoader.loadModule("modules/content2.swf"); }
                         else if (id == "content2") { moduleLoader.loadModule("modules/content3.swf"); }
                         contentShowAnimation.play();
                    });
               contentHideAnimation.play();
               contentId = id;
          } 
          • 2. Re: waiting for the end of effect
            Piotr Wierzgała Level 1

            Thanks Madhav, it works fine for me.