4 Replies Latest reply on Oct 8, 2007 8:04 AM by kglad

    Basic AS3 Language Problem

    umplane
      If i make 1 button, when it "Roll Over", "Roll Out", "Mouse Up" also will play different motion. Is it need to add 3 EventListener to it?

      buttonName.addEventListener(MouseEvent.ROLL_OVER,buttonOver);
      buttonName.addEventListener(MouseEvent.ROLL_OUT,buttonOut);
      buttonName.addEventListener(MouseEvent.MOUSE_UP,buttonUp);

      ********************************************************

      than need add 3 function :

      function buttonOver(event:MouseEvent) {
      buttonName.gotoAndPlay("over");
      }
      function buttonOut(event:MouseEvent) {
      buttonName.gotoAndPlay("out");
      }
      function buttonUp(event:MouseEvent) {
      buttonName.gotoAndPlay("up");
      }

      ********************************************************

      Can i make it to be simple?
        • 1. Re: Basic AS3 Language Problem
          kglad Adobe Community Professional & MVP
          that's as simple as it gets for one button that must have those 3 handlers. if you have more than one button, you can condense your code by using a for-loop to add the listeners and use the same 3 functions for all the buttons once your change buttonName to MovieClip(event.currentTarget).
          • 2. Re: Basic AS3 Language Problem
            umplane Level 1
            I really need make a lot of buttons. haha~
            thx for your answer~ Kglad ^^.
            I have some concept to do this now.
            • 3. Re: Basic AS3 Language Problem
              umplane Level 1
              This is my finally script :

              btnA.addEventListener(MouseEvent.ROLL_OVER,eventHandler);
              btnA.addEventListener(MouseEvent.ROLL_OUT,eventHandler);
              btnB.addEventListener(MouseEvent.ROLL_OVER,eventHandler);
              btnB.addEventListener(MouseEvent.ROLL_OUT,eventHandler);
              btnC.addEventListener(MouseEvent.ROLL_OVER,eventHandler);
              btnC.addEventListener(MouseEvent.ROLL_OUT,eventHandler);
              btnD.addEventListener(MouseEvent.ROLL_OVER,eventHandler);
              btnD.addEventListener(MouseEvent.ROLL_OUT,eventHandler);

              function eventHandler(event:MouseEvent) {
              if (event.type == MouseEvent.ROLL_OVER ) {
              event.currentTarget.gotoAndPlay("over");
              } else if (event.type == MouseEvent.ROLL_OUT) {
              event.currentTarget.gotoAndPlay("out");
              }
              }
              • 4. Re: Basic AS3 Language Problem
                kglad Adobe Community Professional & MVP
                you're welcome. if you have a lot of buttons you can use a for-loop: