Introduction to Flash MX
 |Sofia Home | Content Gallery |
Home
Syllabus
Schedule
Lessons
Assignments
Exams

Lesson 8.4 Object Actions

Take a break before proceeding with this section. It requires your full attention.

Drag a button to the stage. This is the button you will script to stop the wheels, steering wheel, and exhaust. Select this button on the stage and open the Actions Window. You'll notice that the title of the Actions says Actions - Button. When you place an action on a frame the title will say Actions - Frame. We already have a stop action on our stop button which stops the car from moving down the hill. That stop action is actually stopping the movement of the motion-tweened car on the main timeline. The code to stop the main timeline appears in the right pane of the Actions Window shown below.

Select the line with the stop command in the script window by clicking on the line which has the code stop(); between the curly braces.

Go to the View Options drop-down menu on the Actions Panel and change from Normal Mode to Expert Mode. The View Options menu is identified in the image below on the right middle part of the image, right above the words Normal Mode.

Back to Top

Expert Mode enables you to type your script into the script window as if you were typing into a word processor. Position your cursor or insertion point before the stop(); action on line 2. You can identify the line by either selecting View Line Numbers from the View Options drop-down menu or by the status bar on the bottom of the script window.

Position the cursor to the left of the stop action and click on the Target Symbol which is the 4th icon from the left above the script window. This will Insert a Target Path. The Target Symbol looks like a crosshairs in a circle.

When you select this line of code, some text fields will be displayed above the script window. Insert your cursor in the Object: field. Then click on the Insert a target path icon as indicated in the image below. This will open the Insert Target Path window.

The Insert Target Path is another display of the hierarchical tree starting with the _root or main timeline. Expand the plus sign in the car1 instance to display the instances nested within the car1. Select the exhaust instance in the top pane and notice the reference in the Target: field in the mid-lower part of the window. Flash addresses this exhaust instance as: _root.car1.exhaust

Back to Top

In the area below the Target: field, select the following options:

  •  Notation: Dots
  •  Mode: Absolute

Click the OK button to return to the Action Window and see your revised action script displayed:
_root.car1.exhaust.stop();

NOTE:  If you don't see the _root in the insert target path, be sure that you have selected the Absolute radio button for Mode and the Dots radio button for Notation.

Drag the pane divider to the left to expand the script window and hide the set of action books. Insert your cursor between the target _root.car1.exhaust and the method or action stop();. Notice the color coding below.

Insert a dot between the target and the stop so your code now reads:
_root.car1.exhaust.stop();

Notice the color coding now. It's changed. The stop action is in blue.

Return to Normal Mode.

Select the action line between the curly braces by clicking on _root.car1.exhaust.stop();

  • Notice the appearance of 3 fields above the script window.
  • The Object which we are targeting is:_root.car1.exhaust.
  • The Method or action is stop.

We have not set any parameters. An example of a parameter would be a frame number or frame label. For example gotoAndStop ("mute"); - the method is gotoAndStop and the Parameter is the mute frame label. We don't have or need a parameter for the current action.

In the following diagram, I have returned to Expert Mode and selected View Line Numbers from the View Options drop-down menu.

Back to Top

The following code shows comments in actionScript for a goto action. When you use stop and play actions you will not be able to click in the object field from Normal Mode. Be sure to go to Expert Mode to Insert your Target Path. Then, you can return to Normal Mode and view your target in the Object field above the script window.

Now it's your turn to add the tires and the steering wheel to the stop exhaust button. After you successfully target these three nested instances and get them to stop, add actions on the play button to make them all play again when the car continues its path on the hills.

Here's an example of my script to make the exhaust play:

The code says:

on (release) {
     play(); // starts the playback head of the main timeline only but any me will continue to play
     _root.car1.exhaust.play(); // starts the playback head of the exhaust shape tween movie clip
}

Back to Top

You can target the nested symbols of the car1 instance of the car symbol but using the Insert Target Path window. Click on the plus sign to the left of the car1 movie clip instance to expand the tree and view the nested clip instances.

Buttons and actionScript that you need to create:

  • 1 button to stop the car moving down the hill
  • 1 button to stop the nested clips so the tires, steering, and exhaust will stop
  • 1 button to start the car moving down the hill and also start all the nested clips so the wheels and steering will turn and the exhaust will smoke

You will have 3 buttons - only 3 buttons. They will function as above. This script with comments should help you in stopping the other nested clips:

Save your movie. Test your movie.

Back to Top

In the Flash movie that follows I have not scripted the exhaust to stop but I did add some sound effects to the buttons. Make sure you script your exhaust to stop.

INTERACTIVE Flash DEMO

This movie is basic for illustrating targeting nested movie clips. As you develop your Flash skills you can modify this movie so that the user can have more control on individual parts of your movie clips. You will learn to have more precision over sound, location, visibility of objects on the stage, collision detection and more. However with this introduction to scripting movie clips, you've already learnt enough to create some interesting and effective Flash movies. Have fun!

Movie clips can also be used to create pop up menu interfaces. This is too advanced for this course so we will not cover the programming used to create the actions, but take a look at these movies.

INTERACTIVE Flash DEMOS

Roll your cursor over the color button, then click on each of the red, green, and blue color buttons in the movie below:

 

This is the last section of this lesson. Please proceed to the Assignments area.

 

Back to Top

 

Up » 8.1 Movie Clips » 8.2 Scripting Instances » 8.3 The Flash Movie Explorer » 8.4 Object Actions