Start & Stop MovieClip buttons - Flash (AS2)

view all tutorials»


Starting and stopping a flash movieclip is simple, but very useful. For this tutorial I have created an example (below) for you to have a play with using our old friend ‘blob’ from earlier tutorials. You will need a pre-created animated movie clip for this tutorial.

STEP 1

Start a new actionscript 2 file, set the framerate to 30 for smooth animation. Create three layers, one called ‘movie clip’, another called ‘buttons’ and a third called ‘actions’. First select your moviclip layer, and drag your animated movie clip from the library onto the stage, then give this an instance name. I have called mine ‘MC_blob’ for the purpouse of this tutorial.

STEP 2

Now we need to create a couple of buttons, play and stop (or start and stop, tis up to you!). If you are unsure how to do this please view the buttons tutorial. Give these buttons instance names of ‘MC_play’ and ‘MC_stop’. Your stage should now look similar to this:

STEP 3

Now we need to add the actionscript. Select frame 1 on the actions layer and press f9 to enter the actions panel. Enter the following code:

MC_play.onRelease =  function(){
MC_blob.play();
}

MC_stop.onRelease =  function(){
MC_blob.stop();
}

This tells the flash movie that when the play button is released, complete the following function ( “MC_play.onRelease =  function(){” ). The next line telling flash to find MC_blob and play it ( “MC_blob.play();” ). The stop button works in the same way, just swap out the word play for stop!

Hit CTRL and enter and click the buttons, ta-da! A nice simple bit of code that can make your life alot easier!

The Dude

Did this tutorial help you? If so, click the bookmark button, stumble me, add me to your twitter and tell your friends! Alternatively, sign up and leave a comment!

Not what you were looking for? Then leave a comment or email me and we’ll get you the tutorials you need.

Did this post help you? If so help us continue to grow and Digg this page!

If you haven't already, sign up to our RSS feed or register to recieve updates direct to your email!

5 Responses to “Start & Stop MovieClip buttons - Flash (AS2)”

  1. trish

    I have eight buttons moving on a motion path within a movie clip and my question is how do I get them to stop on a mouse rollover and play on rollout?
    Please help


  2. Hi Trish,

    Put the buttons on the motion path into a movieClip (MC_buttons), then use:
    MC_buttons.onRollover = function(){
    this.stop();
    }
    MC_buttons.onRollout = function(){
    this.play();
    }
    This should create the effect you are after.
    The Dude

  3. Maktavish

    Hey, First of all - Great tutorial!!!
    Secondly, do you know where I can find AS2 for controlling a movieclip like a button? What I am trying to do is have an animated house floorplan and when you mouse over each line a section / wall elevation will rise up.
    I’d appreciate any help, asap.

    Thanks.


  4. Hi Maktavish,

    Tutorial right here - Advanced Buttons

    The Dude

  5. Thompson

    Hi, thanks for the tutorial,
    What I am trying to do is have 7 buttons start (when clicked) 7 different videos in the same video player or location. How or where on the time line do I place the videos and have the buttons (which are going to be thumbnail pics) have a simple rollover effect and and play each individual video clips? I am sorry if the question sound basic or don’t make much sense but I am new to the world of flash.
    Thanks in advance!

Leave a Reply