12 Replies Latest reply on Dec 2, 2011 4:55 PM by iFlashAppsToo

    Need: loop is playing, click button, loop finishes then starts next loop

    StudentOfSpellin

      My girlfriend and I are animators and are learning Flash AS3. We have learned to set up a scene with a character (in a 4 second fidget loop) with a button to the same character (in a 4 second dance loop) but when the button is pushed there is a jump. The first loop doesn't finish to the last frame (which matches up with the first frame of the dance loop).

       

      Eventually we would like many buttons that link to different dance moves but it's important that the animation is seamless between the loops. Any advice or tutorial pointers on how this can be done would be appreciated.

        • 1. Re: Need: loop is playing, click button, loop finishes then starts next loop
          Ned Murphy Adobe Community Professional & MVP

          What code is your button using and what is the intention of the code?  How does it relate to the animation?

          • 2. Re: Need: loop is playing, click button, loop finishes then starts next loop
            kglad Adobe Community Professional & MVP

            either start a loop when a button is clicked (that repeatedly checks your characters currentFrame and then redirects character to the appropriate frame) or, less wisely, assign a variable's value that's checked on the last frame of your animation and directs the character timeline to the appropriate frame.

            • 3. Re: Need: loop is playing, click button, loop finishes then starts next loop
              StudentOfSpellin Level 1

              Ned, we are new so we have two extra layers on the timeline, with the two 2 second loops in each, and a basic button that connects the first to the second. Each layer is also 2 seconds. When the button is pressed there is a beat before the switch over but quite often it passes the last frame and ends on a random frame (which doesn't match the first frame of loop two).

               

              kglad, when you say "redirects character to the appropriate frame" I'm hopping you mean let the character's frames just keep playing to the last frame (rather than Jump to last frame)? I was wondering how to script the character to always play to the last frame, so all loops would match, but your saying it's better to have the 'button' tell the first loop to play to the last frame? I'm all for the wiser way but I'll need your wisdom on what and where to write. I've heard Flash is good for animation but I can't find any tutorials to link character loops together like this. The program itself makes it hard by not accepting video, we have to lay each PNG in the timeline to get a movie clip, ugg.

              • 4. Re: Need: loop is playing, click button, loop finishes then starts next loop
                StudentOfSpellin Level 1

                I always lost my alpha channel when I imported video but I finally learned if the background is black in the avi file the flv conversion and import into Flash works fine. That's solved but the loops still jump when one passes to the other. If the character was the button and we click on him, could the click turn off his looping so he would then just play thru to it's end and into the next layer (animated loop) on the timeline?

                • 5. Re: Need: loop is playing, click button, loop finishes then starts next loop
                  kglad Adobe Community Professional & MVP

                  kglad, when you say "redirects character to the appropriate frame" I'm hopping you mean let the character's frames just keep playing to the last frame (rather than Jump to last frame)?

                  correct, let the frame sequence complete and then at the end (of your jitter frames, for example) use a goto (to the dance frames) and vice-versa.

                   

                  I was wondering how to script the character to always play to the last frame, so all loops would match,

                  again, start a loop when a button is clicked (that repeatedly checks your characters currentFrame and then redirects character to the appropriate frame)


                  are you using as2 or as3?

                  • 6. Re: Need: loop is playing, click button, loop finishes then starts next loop
                    StudentOfSpellin Level 1

                    We're using AS3. How would we script the character to be the button that tells it to finish it's loop and then start the next loop? This script could be on every character loop and make things easier?

                    • 7. Re: Need: loop is playing, click button, loop finishes then starts next loop
                      kglad Adobe Community Professional & MVP

                      don't make it a button, leave it a movieclip.  label character's frames fidget_start, fidget_end, dance_start, dance_end etc in the obvious way and use:

                       

                      var nextframe:String;

                       

                      fidget_btn.addEventListener(MouseEvent.CLICK,nextF);

                      dance_btn.addEventListener(MouseEvent.CLICK,nextF);

                      etc

                       

                      function nextF(e:MouseEvent):void{

                      nextframe=e.currentTarget.name.split("_")[0]+"_start";

                      if(character.currentFrameLabel.indexOf("end")>-1){

                      character.gotoAndPlay(nextframe);

                      } else {

                      character.addEventListener(Event.ENTER_FRAME,enterframeF);

                      }

                      }

                       

                      function enterframeF(e:Event):void{

                      if(character.currentFrameLabel.indexOf("end")>-1){

                      character.gotoAndPlay(nextframe);

                      character.removeEventListener(Event.ENTER_FRAME,enterframeF);

                      }

                      }

                      • 8. Re: Need: loop is playing, click button, loop finishes then starts next loop
                        StudentOfSpellin Level 1

                        okay, here's what I've got. Without this the first loop is constant. With this script in, the first loop plays and the next loop plays half a second and then back to the start of loop one. It does this 3 times and then plays the second loop. It then goes back to the first loop but we still hear the audio of the second loop (he says welcome a second time now). The two buttons don't seem to change this cycle. Arg. Hopefully I didn't fill in your script correctly? Here it is so you can point to the symbol I missed. Kidding.

                         

                        BTW, p1dance0 is the (pirate #1) fidget loop, p1dance1 is the first dance loop. This script is on frame 1 of the AS3 layer. Below this is the buttons layer, the two loop layers and a simple background layer. There are no scripts to make the loops as they are stretched out on the timeline with the frames they need (end to end). In case you thought I already had a script in there to make the loop. 

                         

                         

                         

                        var nextframe:String;

                         

                        dance0_btn.addEventListener(MouseEvent.CLICK,nextF);

                         

                        dance1_btn.addEventListener(MouseEvent.CLICK,nextF);

                         

                         

                        function nextF(e:MouseEvent):void{

                         

                        nextframe=e.currentTarget.name.split("_")[0]+"_start";

                         

                        if(p1dance0.currentFrameLabel.indexOf("end")>-1){

                         

                        p1dance0.gotoAndPlay(nextframe);

                         

                        } else {

                         

                        p1dance0.addEventListener(Event.ENTER_FRAME,enterframeF);

                         

                        }

                         

                        }

                        function enterframeF(e:Event):void{

                         

                        if(p1dance0.currentFrameLabel.indexOf("end")>-1){

                         

                        p1dance0.gotoAndPlay(nextframe);

                         

                        p1dance0.removeEventListener(Event.ENTER_FRAME,enterframeF);

                         

                        }

                         

                        function nextF(e:MouseEvent):void{

                         

                        nextframe=e.currentTarget.name.split("_")[0]+"_start";

                         

                        if(p1dance1.currentFrameLabel.indexOf("end")>-1){

                         

                        p1dance1.gotoAndPlay(nextframe);

                         

                        } else {

                         

                        p1dance1.addEventListener(Event.ENTER_FRAME,enterframeF);

                         

                        }

                         

                        }

                         

                         

                         

                        function enterframeF(e:Event):void{

                         

                        if(p1dance1.currentFrameLabel.indexOf("end")>-1){

                         

                        p1dance1.gotoAndPlay(nextframe);

                         

                        p1dance1.removeEventListener(Event.ENTER_FRAME,enterframeF);

                         

                        }

                        }

                        • 9. Re: Need: loop is playing, click button, loop finishes then starts next loop
                          kglad Adobe Community Professional & MVP

                          what's the reference to your character?  what are some of your frame labels in your character?

                          • 10. Re: Need: loop is playing, click button, loop finishes then starts next loop
                            StudentOfSpellin Level 1

                            The "p1dance0" refers to the main character loop. On both this and the "p1dance1" character loop I've labeled the first keyframe "p1dance0_start" and the last keyframe "p1dance0_end". I was asuming the namesplit meant it could be anything as long as it ended with _start.  

                             

                            I've just tried replacing these with p1dance0_start, etc, in the code to reflect exactly what's on the timelines but still no change

                            • 11. Re: Need: loop is playing, click button, loop finishes then starts next loop
                              kglad Adobe Community Professional & MVP

                              you have a character movieclip.  what's your movieclip instance name? 

                               

                              that movieclip has several start keyframes and end keyframes.  each set of start and end frames along with the intervening frames constitutes some character animation. 

                               

                              your keyframes have labels, "p1dance0_start","p1dance0_end","p1dance1_start", "p1dance1_end","p1dance2_start","p1dance2_end" etc?

                              • 12. Re: Need: loop is playing, click button, loop finishes then starts next loop
                                iFlashAppsToo Level 3

                                think outside the box

                                 

                                you have 10 movieclips

                                 

                                and you have 10 buttons to press, each relating to a movieclip

                                 

                                //---

                                 

                                set a variable on a button press to track which movieclip to play next

                                 

                                set a variable to keep track of the movieclip currently playing

                                 

                                add a listener to the currently playing clip to know it's currentframe

                                 

                                if the currentframe of the movieclip that is currently playing is on the last frame you can check to see which clip to play next.

                                 

                                if you had pressed a button which set a new clip to play, it will play the next clip. you should now reset the variable for the movieclip currently playing to this new clip

                                 

                                if you didn't press any buttons, it will keep replaying the same clip