1 Reply Latest reply on Aug 10, 2017 2:19 PM by RandomlyFish

    Hover script not working in animation AS3

    iezqandarzulqarnaen

      Hye guys,

       

      This is a continuous thread ofButton Hover.

       

      After applying code form just.emma i tried to make some animation for the buttons.

       

      the problem come after the button animation stop, the button hover is not working.

       

      here is the .fla file : Dropbox - Adobe Animate CC

       

      I have made two(2) buttons, 1 is static that hover is working & another 1 is with animation that hover not working.

       

      Kindly help me inspect what is the problem.

       

      Thank you.

        • 1. Re: Hover script not working in animation AS3
          RandomlyFish Level 3

          The code you have written for all the buttons run as soon as you start playing, but the button that the code is trying to access, does not exist at that point. So one way to fix this would be to keep each of the buttons off screen at the start. Another way to solve it would be to execute the code once all buttons are on the screen, but I would recommend the first solution.

           

          Also, here's one way you could write the code, to make it a lot less repetetive:

           

          function CreateButton (_button : DisplayObject, _animation : MovieClip) {
          
               var over : Function = function () {
                    _animation.gotoAndPlay("animate");
               }
          
               var out : Function = function () {
                    _animation.gotoAndStop(1);
               }
          
               _button.addEventListener(MouseEvent.MOUSE_OVER, over);
               _button.addEventListener(MouseEvent.MOUSE_OUT, out);
          }
          
          CreateButton(subMenuStatic_mc.glass_btn, this.glassdept_mc);
          CreateButton(subMenuAnimate_btn.glass_btn2, this.glassdept_mc);
          

           

          That way you only have to write one line of code for each new button you want to add. And if you want to change the behaviours of the buttons, you only need to change it inside the CreateButton function, instead of on multiple different lines of code.