3 Replies Latest reply on Jun 2, 2016 6:01 AM by Colin Holgate

    apply action on all frames

    alia9955927

      Hi there.

      i am trying to add home button to my programme

      is there a way to apply an actionscript to the button and make it work in all frames?

        • 1. Re: apply action on all frames
          Colin Holgate MVP & Adobe Community Professional

          If you made the button as a movieclip instead of a button, you could put the script inside the button. It would be something like this:

           

          addEventListener (MouseEvent.CLICK,gohome);

           

          function gohome(e:MouseEvent){

            MovieClip(parent).gotoAndStop("home");

          }

           

          If you wanted to sow the user a pressed state for a moment, you could have two frames, the second one look like a pressed version of the graphic Then this would be the whole script, which you would put into frame 1 of the movieclip:

           

          stop();

          addEventListener (MouseEvent.CLICK,press);

           

          function press(e:MouseEvent){

            gotoAndStop(2);

            setTimeout(gohome,500);

          }

           

          function gohome(){

            MovieClip(parent).gotoAndStop("home");

          }

          • 2. Re: apply action on all frames
            mhunter Level 1

            If the code is on its on layer and there are no key frames, the code will always work, right?

            • 3. Re: apply action on all frames
              Colin Holgate MVP & Adobe Community Professional

              Pretty sure that even if code is on a layer with other things, and there are keyframes after it, it should still work. The advantage of putting the code in the movielcip itself would be that you can put a copy of the button in to just the places it's needed, without having to add code to the timeline for each case.