• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Hour 14. Using ActionScript to Create No... > Task: Use with to Target Nested Inst...

Task: Use with to Target Nested Instances

In this task we use the with Action to stop instances of wheels that are inside a clip of a car.

We'll need a car with rotating wheels like we made in Hour 12 in the task titled “Use a Movie Clip to Make a Rotating Wheel.” If you recall we achieved this by working from the inside out. First we made a clip of a wheel called “Plain Wheel” (a circle with lines that would be noticeable when it rotated). Then we used an instance of the Plain Wheel to create another clip called “Rotating Wheel.” Rotating Wheel contained an instance of Plain Wheel in frame 1 and frame 20. A Motion Tween to rotate the wheel was set in the first keyframe of Rotating Wheel. Finally, two instances of Rotating Wheel were used in the creation of the Car. Either revisit the task in Hour 12 or create the Rotating Wheel clip and we'll pick up from there.

Drag one instance of Rotating Wheel to the Stage. Test the movie to confirm the wheel is rotating and take note what direction it's rotating.

Drag another instance of Rotating Wheel and place it to the left of the other instance. With the Properties panel, name one of the instances front_wheel and the other back_wheel as in Figure 14.12.

Figure 14.12. Using the Properties panel, we name each instance of the Wheel so they can be addressed individually.

Draw a car body around the two wheels (nothing fancy). Select everything and choose Insert, Convert to Symbol (or press F8). Name this new Movie Clip Car.

Onstage you have an instance of Car, but it has no instance name yet. Use the Properties panel to name this instance the_car. (Notice that clip instance names should have no spaces and should not begin with a number.)

Finally, insert a keyframe at frame 40 and move the_car to another place onstage. In the first keyframe, set Motion Tween.

In a new layer, draw a rectangle to be used as a button. Select it and covert it to a symbol called myButton and make sure to set its behavior to Button. Copy and paste this button so we have two instances. Use the Properties panel's Color styles to Tint one green and one red.

Select just the red instance of myButton. Open the Actions panel. Insert a stop Action (and leave it with the default release mouse event).

Test Movie and you'll see the stop button stops the car from moving across the screen, but it doesn't stop the wheels from spinning. We need to add additional Actions to stop each wheel.

Back in Flash, access the Actions for your button, select the stop Action already in the Script Area, and click the plus button, Actions, Variables, with, as in Figure 14.13.

Figure 14.13. Within the release mouse event, we insert the with Action after the stop Action.

Click in the Object field for the with Action's parameters then click the Insert Target Path button right above the Script Area; it looks like cross hairs.

The Insert Target Path dialog box pops up with a hierarchy of named clips instances in your movie. Next to Car, click the plus sign to see the named clip instances inside it. Click front_wheel and then click OK. See Figure 14.14. Notice the object field should now read the_car.front_wheel (this follows the form of general to specific).

Figure 14.14. Using the Insert Target Path dialog box, we can target an individual instance.

Now we have to say what we want to do with the front_wheel instance. Select the line containing with and then double-click the stop Action from the Toolbox List to add it after the with Action. The result should look like Figure 14.15.

Figure 14.15. Between the two curly braces of the with Action we insert the stop Action.

Repeat the process to target the back_wheel instance. Make sure when you add another with Action that it gets placed before the last curly brace of the mouse event, but after the ending curly brace for the first with Action. The final script should look like Figure 14.16.

Figure 14.16. The finished script targets both instances of Rotating Wheel.

Test Movie. When you click the red button, the car and both wheels stop. You could repeat this process with the play Action on the green button to allow a user to make the car move again.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint