4 Replies Latest reply on Oct 5, 2009 6:38 AM by oharaandrewlp360

    button that begins an animation once clicked

    oharaandrewlp360

      Hi there,

       

      I don't have much experience with buttons and barely any with action script.  I am trying to make a button that is a non-animated symbol on up, a glowing version of the symbol on over, and on down the symbol swaps to an animated symbol that moves across the screen.

       

      But, on the down state, the symbol does not animate like it is supposed to.  When I hold the mouse button down, the glow goes away, but the symbol just does not animate as specified in the symbol that appears during the down state.

       

      I tried experimenting with making the button move on the main timeline, adding a stop() command in one of the layers of the up-state symbol, and then adding a play() command to one of the layers of the down state symbol, but nothing seems to work.

       

      Am I doing this completely wrong?

      I have done a good deal of animating in flash before, but nothing interactive like this.

       

      I've uploaded my CS4 .fla file if my explanation doesn't do justice.

        • 1. Re: button that begins an animation once clicked
          robdillon Most Valuable Participant

          You don't need the play() inside the movieClip for the down state. If you don't specify a stop() in a movieClip it will loop, which is what you want. When I run your movie I see the animation in the down state of the button. Its slow but it does animate. If you raise the frame rate or shorten the animation, it will change more quickly.

          • 2. Re: button that begins an animation once clicked
            oharaandrewlp360 Level 1

            Yes, I just realized now that you said it that the button does animate if I hold the button down.  I have now put the dow-state symbol inside another symbol that moves in a classic tween.  Now the rabbit moves his arms and legs and moves across the screen.  This is close to the effect that I am looking for, but I need to hold the button down for it to work.

             

            Is there any way to make the same animation happen by just clicking and releasing the button?

             

            I have uploaded a new CS4 .fla and.swf to show how I have the button moving across the screen.

            (Yes I know the arm and leg animation is horrible; I don't really make animated humanoid objects much)

            • 3. Re: button that begins an animation once clicked
              robdillon Most Valuable Participant

              Your animation is working now because you are exploiting a button's operation. The two animations run based on the user holding the cursor over the rabbit and holding the mouse button down. What you really want to be doing is to have the animation run autonomously when the user clicks on the button. To accomplish this you'll need a function.

               

              Take a look at the changes that I made.

              • 4. Re: button that begins an animation once clicked
                oharaandrewlp360 Level 1

                O.K I see the changes that you have made, and even though I do not fully understand the actionscript, I have figured out how to work with the onEf function; but before I mark this question as solved, I have a few questions:

                 

                First, is the 'bugs' reference referring to the name of the layer 'bugs'?

                 

                Also, since I know some of other programming laguages, I have figured out how to add to this function like so:

                 

                function onEf(event:Event):void {
                    if(isRunning) {
                        if (bugs.x < 300) {
                        bugs.x += 5;
                         }
                        if( bugs.x < 600) {
                            bugs.x += 1;
                        }
                    }
                }

                 

                But, one of the criteria for this animation is for bugs to stop for a specified ammount of time, and then continue moving.  I could probably do this:

                 

                if (_______) {

                     bugs.x += 0;

                }

                 

                but how would I ask it to wait until a certain amount of time has passed?