4 Replies Latest reply: Jan 16, 2013 6:04 PM by kglad RSS

    Reusing animation with different endings?

    mentalcase129 Community Member

      Hopefully the solution I'm looking for isn't too intensely complicated but the question is a little difficult to explain so I'm apologizing in advance for maybe over explaining.

       

      Using Fash CS5 with Actionscript 3.  I'm putting together a timeline based website.  Upon entering the site there is a cluster of buttons, organized in sort of an artistic manner.  The idea is once you click on any of the 3 or 4 buttons, they rearrange themselves to appear along the top of the screen a little more conventionally and the corresponding section of the website will then appear in the new content window that appears during the action.  From this point on the the new, simpler layout will be the navigation for the rest of the user's time on the site.  The animation of this action is simple enough and already done.  Here's the trick though...as I said there are 3 or 4 different buttons to choose from and we have no way of knowing which button the user will click on first.  The animation can be copy and pasted for each section of the site of course but we don't want to snap back to the beginning and replay that transitional animation every time some one navigate to a different section...we only want that animation to play the first time the user clicks on one of the first buttons. 

       

      So what I'm wondering is if there is a way with actionscript to program those buttons as they first appear to playback the same animation(it could be placed in a movie clip if necassary) but when the animation is done playing it navigates to a different frame on the timeline.  Does that make sense?  Basically I want to play forward on the timeline but then when it reaches a certain point it jumps to a designated spot on the timeline depending on which button you clicked to play the animation in the first place.

       

      I already have a couple of ideas of how to achieve this using multiple versions of buttons etc., but I'm thinking if there's a way to set it up with actionscript we can maybe keep from getting the timeline overly conveluted.

       

      Thanks.

        • 1. Re: Reusing animation with different endings?
          kglad CommunityMVP

          sure, you can wait until your artsy animation completes before executing your gotoAndPlay.  just have your buttons assign a variable (eg, nextframe_label) value.  at the end of your artsy animation execute your gotoAndPlay(nextframe_label)

          • 2. Re: Reusing animation with different endings?
            moccamaximum Community Member

            If your buttons are MovieClips (dynamic class), you can create own properties for them. (It doesn`t work if they are Graphics/Buttons)

            In your case for example a property "clicked".

             

            //at the beginning of your application all the Buttons are untouched

            btn.clicked = false;

             

            Then in your eventListener for the Click-Event, you

            adjust the behavior of the button due to the state of this property.

             

            btn.addEventListener(MouseEvent.CLICK, clickHandler);

            function clickHandler(e:MouseEvent):void{

                if(!e.currentTarget.clicked){

                    e.currentTarget.clicked = true;

                    //do the animation

                }

                else{

                  //skip the animation

                }

            }

             

            That way, your application memorizes, if the user has already clicked the button, or not, and reacts accordingly

            • 3. Re: Reusing animation with different endings?
              mentalcase129 Community Member

              Thanks...I'll play around with both of those.  Here's another question though, cuz as I was playing with it more I had another idea.  If I have a button programmed to play a movieclip on the timeline...can I attach a code to the movieclip so that when it's done playing it navigates to a different spot on the timeline?

              • 4. Re: Reusing animation with different endings?
                kglad CommunityMVP

                yes.

                 

                if you want to direct the movieclip parent timeline use:

                 

                MovieClip(parent).gotoAndPlay("some label");