Start & Stop MovieClip buttons - Flash (AS2)

view all »


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.

Vote in HexoSearch Help me out by voting for this tutorial

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

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

16 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!

  6. Luke

    Thank you for this information. Im currently working on an audio gallery page. Each song name is assigned a movie clip and when user presses MC, it plays a particular track. But my problem was that the other buttons on the page would not reset back to frame one which shows the stop button. After reading ur page, I came up with this script which each button has.

    on (press){
    stopAllSounds();

    _root.MC_A.gotoAndStop (”1″)
    _root.MC_B.gotoAndStop (”1″);
    _root.MC_C.gotoAndStop (”1″);
    _root.MC_D.gotoAndStop (”1″);
    play();
    }

    Thanks for the information…just wanted to give you a pat on the back for helping me figure this out.


  7. Thanks Luke :D

    The Dude

  8. Mela

    Great tutorial!

    I’m having a problem with 2 movie clips that run non stop.

    I think I have 2 problems:
    1) The move clips need to stop at 15 seconds. But at the moment, the movies within the movie clips are set at a loop

    2) I’d like them to stop on rollover of the entire banner size. And start again on rollout. Any tips?

    Thanks!

  9. Geoffrey Bond

    All,

    I have had a go at creating a bouncing ball, accompanied with stop and start buttons. I would be very grateful if you could supply me with an email address, so I can email you my attempt to have a look at and let me know where I am going wrong?

    Regards,
    Geoff

  10. oneil

    So my FLV videos play just fine, however when I click on any of the navigation buttons to visit another section of my website, the audio keeps on going. There must be some simple AS to stop the audio once a button is clicked. As it is now, the user has to stop the FLV video manually by clicking the stop button on the FLV playback component. I am using AS3,

    this is my codeing everythink works will i just cant stop the sound wiles viewing another video….

    but1.addEventListener(MouseEvent.CLICK,on27Click);
    but2.addEventListener(MouseEvent.CLICK,on28Click);
    but3.addEventListener(MouseEvent.CLICK,on29Click);
    but4.addEventListener(MouseEvent.CLICK,on30Click);
    but5.addEventListener(MouseEvent.CLICK,on31Click);
    but6.addEventListener(MouseEvent.CLICK,on32Click);

    function on27Click(e:MouseEvent):void
    {
    gotoAndStop(”27″);
    }

    function on28Click(e:MouseEvent):void
    {
    gotoAndStop(”28″);
    }

    function on29Click(e:MouseEvent):void
    {
    gotoAndStop(”29″);
    }

    function on30Click(e:MouseEvent):void
    {
    gotoAndStop(”30″);
    }

    function on31Click(e:MouseEvent):void
    {
    gotoAndStop(”31″);
    }

    function on32Click(e:MouseEvent):void
    {
    gotoAndStop(”32″);
    }

  11. A Rehman

    this tutorial is very easy .very good i am very happy thanks for shairing. i want more more and more help and i am sure you will help me in this action scripting
    thank you very mucy

  12. Greg Walton

    Thankyou very much for this, i’d been searching for days to find an easy tutorial for my first flash project.
    A favour to ask though, could you tell me how i am able to stop the movie and not loop?
    I’ll keep looking through your site
    again - many thanks


  13. Just add a stop(); on the last frame in your actions panel :)

  14. ralf

    could someone please help me on how to add a start button on the timer

  15. nushi

    Hi

    This was really helpful! What would the AS be if i wanted to add a forward and backward btn? Meaning a btn that when pressed would skip forward a few frames ahead and another btn to skip a few frames back in the opposite direction.

    many thanks!
    Nushi

  16. nushi

    so in the meantime, i found this on another forum (actionscript.org)posted by oldnewbie and it seems to work…

    Set X as the current frame…

    this.onEnterFrame = function(){
    _global.X = _level0._currentframe;
    };

    On a button…

    on(release){
    _level0.gotoAndStop(_global.X+60);
    }

Leave a Reply