In this example, we'll look at using the playhead commands play and stop to control a continuously looping movieclip. In the game above, which we'll re-create later in this section there are several movieclips which provide the motion and interactive elements of the movie. The bees are movieclips which contain bee graphics following a motion-guide path, the control buttons on the left are single-frame movieclips, and the flowers are also single-frame movieclips, which allows detection of collisions between a bee and one of the flowers. In the game, points are accrued when one of the bees is stopped while touching that particular flower.
Open beegame_start.fla (available via free download link at right) to follow along with the notes in this section. Look in the library of the fla (ctrl-L) and edit the flyingbee1 movieclip by double-clicking on its icon. (Alternately, you can double-click the instance bee1_mc on stage to edit it in place.) You'll see two layers in the movieclip: one layer with a bee graphic (containing another movieclip named wings_mc) and a motion guide layer. If you scrub along the timeline of the movieclip, you'll see that the bee follows that guide in a continuous loop. Since the point of the game is to use the controls to start and stop the bees, the playhead commands needed are play and stop, respectively.
To make start and stop controls for one of the bees, do the following:
This is the code you should have in frame 1:
beestop_mc.onRelease = function() {
bee_mc.stop();
}
beestart_mc.onRelease = function() {
bee_mc.play();
}
and the movie should look like this:
Notice when you stop the bee in the movie above, its wings don't stop. That may be fine, but if you do want to stop the wings, you'll need to address them properly. Remember that our code is going in frame 1 of the main timeline and wings_mc is not on that same timeline so you can't just do wings_mc.stop() to make them stop.
Instead you need to provide a path-to-instance from the main movie to the nested wings movieclip. Look at the diagram below to see how to address (from the main timeline) a movieclip nested within another. (Notice that although wings_mc is actually nested inside a graphic that is nested inside bee_mc, the graphic is irrelevant in terms of actionscript -- graphic symbols are not addressable with actionscript, so nesting mc1->graphic->mc2 is the same as just nesting mc1->mc2 as far as the actionscript is concerned.)

Exercise 1:
Drag two more controls onto the stage and call them wingstop_mc and wingstart_mc. Add code to frame 1 to make the wings start and stop (independently from the movement of the bees along the timeline. The movie should look and function something like:
If you get stuck, open beewingstop.fla (available by subscription from link at right) and look at the code.
Exercise 2:
Change the code in frame 1 so that beestart_mc makes the bee move and the wings beat, and beestop_mc makes the bee stop and the wings stop (hint: each function will need two lines of code in it, not just one).
last update: 30 Aug 2006
Discussed on this page:
control continuous loop movieclip, play, stop, address nested movieclips
Files:
beegame_start.fla
(free download)
beewingstop.fla
In asbasics.zip, password required
Subscription:
A password may be obtained by subscription
An access password will be emailed to the address you specify within 24 hours of receipt of payment, and will remain active for 30 days thereafter. A list of all files currently available at the site may be viewed here.
Student Samples
Bee Controller with Multiple Controls by Jim Pratt (requires Flash 8 player)