7 Replies Latest reply on Dec 10, 2009 1:34 PM by sarahgrba

    Creating a replay button

    sarahgrba

      Okay - I'm super new at this whole thing so my question may sound stupid.

       

      I've created a simple animation (falling snowflakes with some text that pops in and out) and I wanted to create a button that would replay it at the user's command. I've searched everywhere for the code or how to do this, but I've found nothing of relevance. Can one of you help me please?!

        • 1. Re: Creating a replay button
          Ned Murphy Adobe Community Professional & MVP

          Do you know how to code a button?  What version of actionscript are you using?

           

          If you can code a button, then the only command you'll probably need in the button's function is....

           

          gotoAndPlay(1);

          • 2. Re: Creating a replay button
            sarahgrba Level 1

            No, I don't know how to code a button. Maybe I should have started there. :-)

             

            Any idea where I can find coding a button?

            • 3. Re: Creating a replay button
              Ned Murphy Adobe Community Professional & MVP

              If you can indicate which version of actionscript your file is using, then I (or someone) can help.

               

              Do you know how to create a button symbol?  If not, draw a rectangle on the stage, select it, and choose Modify -> Convert to Symbol -> choose Button.  You can dress it up later on by doubleclicking it to edit its appearance.  Once you have the button on the stage where you want it, you select it and assign it an instance name in the properties panel... the instance name will be used to communicate with the button using actionscript code.

              • 4. Re: Creating a replay button
                sarahgrba Level 1

                So sorry, Ned. I'm using Action Script 3.0

                • 5. Re: Creating a replay button
                  Ned Murphy Adobe Community Professional & MVP

                  Read thru first....

                   

                  Once you have that button created and have assigned it an instance name (let's say you named it "btn")... in an actions layer (create one if you don't have one), create a keyframe in the same frame as where the button is on its layer, select that keyframe and open the Actions panel (Window -> Actions).  Enter the following code in the Actions panel...

                   

                  function startOver(evt:MouseEvent):void {

                       gotoAndPlay(1);

                  }

                   

                  btn.addEventListener(MouseEvent.CLICK, startOver);

                   

                  If you movie is stopped at the last frame, then you may already have an stop(); command in the last frame which is probably where you want to put the button code as well.

                   

                  In that code above there are three things that I named arbitrarily...

                   

                  startOver - the function name could be anything you want to name it as long as it complies with naming rules

                   

                  evt - the event listener throws an argument to the event handler function, evt is a variable representing that argument

                   

                  btn - this is the instance name assigned to the button

                  • 6. Re: Creating a replay button
                    sarahgrba Level 1

                    After some playing around, I got it!

                     

                    Thank you so much for your help!!!!!!

                    • 7. Re: Creating a replay button
                      Ned Murphy Adobe Community Professional & MVP

                      You're welcome.... messing around with Flash is the key to learning