In this lesson, we'll review frame labels, frame and button actions, and we will continue to distinguish individual movie clip symbols' timelines from one another and from the main timeline.
In the car movie, we have a motion tween of the car moving down the hills and a parked car with its wheels rotating, steering wheel turning and exhaust smoking. Both instances of the car symbol in Scene 1 are the same movie clip symbol made up of nested movie clip symbols: 2 instances of the wheel movie clip symbol, 1 instance of the steering wheel movie clip symbol, and 1 instance of the exhaust movie clip symbol.
Let's stop the car that's moving down the hill first since you already learned how to use the stop action in a previous lesson. To do this, create a button and assign it the stop action. The stopaction stops all the action on the main timeline. This will stop the car whenever we release the stop button. There is one important movie clip feature to remember. A movie clip has its own timeline independent of the main timeline or _root. When we stop the movement of the playback head on the main timeline, all movie clips will continue to play on their own timelines. You'll see this in action when we stop the car. The wheels, steering, and exhaust movie clips will continue to play until we target their individual timelines and assign a stop action to their timelines.
After I create a button to stop the movement of the car down the hills, I'll create another button to start the car again. We'll assign this button the play action. This will start the car when we release the start button. The play action will continue the movement of the playback head from where it was stopped. It will not automatically return the playback head to the beginning of the timeline. Flash movies loop by default. When the playback head reaches the last frame it will automatically replay the movie from frame 1 if you haven't assigned any scripts to any of your frames.
1. Insert a layer on the main timeline called but-stop. Drag an instance of a button symbol to your stage. You can use the Common Libraries>Buttons or create a new button.
2. To assign the actionScript "stop" to but-stop, select the button on the stage, and open the Actions Window. Select "stop" from the left pane and double-click to set the code in the right pane. You can also drag the stop action from the left pane to the right script window. You'll notice that the on (release) event handler was added to line 1 by default. Flash is smart enough to know that we're creating an action on a button and it automatically adds the event handler. You can modify the handler to rollOver, rollOut, etc, but for now, keep it to on (release). Please note that your Actions Window should indicate that you have selected a button and NOT a frame. This stop action will stop the playback head wherever it happens to be on the main timeline at the time you release the button.
Add the text 'stop' below the button to inform the user of the purpose of this button. Save your movie.
3. Insert a layer on the timeline called but-play. Drag an instance of a button symbol to your stage. Assign the script "play" to but-play. This will tell the playback head to move forward from the frame in which it was stopped. Add the text 'play' below the button. Save your work. Test your movie.
This is all well and good. The car stops just when we want it to stop and moves forward when we tell it to. But the wheels, steering wheel, and exhaust keep moving when the car stops. What's up with that?
This is the crux of movie clips. Each movie clip is working on its own independent timeline. The stop and play buttons we added only affect the main timeline of the movie. In order to stop the wheels and the steering wheel, assign actions that target the timelines of each movie clip.
This is worth repeating. Assign actions that target the timelines of the nested movie clip instances.
Flash makes it easy for us to learn how to target a path to our movie clips. This addressing system enables you to have more control over your movie's timeline. If you follow along, you'll be able to apply these steps to other movie clip symbols and present a more interactive experience for your users.
A Targeting We Will Go!
Open the car symbol in symbol editing mode by double clicking on the car symbol in the library.
I have selected one instance of the wheels movie clip symbol inside the car symbol editing mode and have given this symbol the Instance Name of: backtire.
Name the front wheel symbol Instance Name: fronttire.
Name the steering_wheel symbol instance: steering.
Name the exhaust symbol movie clip instance: exhaust.
This image displays the selected exhaust movie clip symbol which I named exhaust. You can name an instance name the same as the symbol name or not.
You can tell that the exhaust movie clip is selected because it's outlined in a turquoise blue line on the stage and the Properties identify the clip as: Instance of: exhaust in the area right above the Swap... button to the right of the movie clip Behavior drop-down menu.
Familiarize yourself with the Flash interface so that you know where you are and don't get lost. You can also look above the stage at the breadcrumbing navigation and see that right now, you are in the car movie clip symbol editing mode.
Changing the Instance Definition
Changing the Instance Definition in your main movie timeline does not change the Symbol Definition in the Library and vice versa. When you drag an instance of the symbol from the library to the stage, Flash knows what the symbol behavior is for that symbol. If it's a graphic symbol, you can change that particular instance to a button symbol on the stage but the original graphic symbol will remain a graphic symbol in the library.
If you redefine a behavior of an instance, it's valid only for that particular instance. It will not change the behavior of the symbol in the library.
Most of the demos in this course are created using nested instances of movie clips with frame labels and action scripts.
Please continue to the next section of this lesson.