|
|
|
|
| Tutorial |
To perform collision detection on two movie clips (see hit_test.fla):
1 Drag two movie clips to the Stage and give them the instance names car and area.
2 Create a dynamic text box on the Stage and enter status as the instance name in the
Property inspector.
3 Select area and choose Window > Actions if the Actions panel is not already visible.
4 To apply the hitTest test, in the Actions toolbox, click the Actions category, click
Miscellaneous Actions, and double-click evaluate. Enter the following code in the
Expression text box:
_root.status=this.hitTest(_root.car);
Flash automatically adds the onClipEvent handler.
5 Highlight the onClipEvent action and select enterFrame as the event.
6 Select car from the jump menu at the top of the Actions panel.
7 To apply movement to the car, in the Actions toolbox, click the Actions category, click Movie
Clip Control, and double-click startDrag.
8 To limit the car’s movement, select the Lock Mouse to Center and Constrain to Rectangle
options, and enter 4 for Left, 70 for Top, 396 for Right, and 273 for Bottom.
Flash automatically adds the onClipEvent handler.
9 Highlight the onClipEvent action in the Script pane and choose the Mouse down event.
Your code should look like this:
onClipEvent (mouseDown) {
startDrag("", true, 4, 70, 396, 273);
}
10 To stop the car, in the Actions toolbox, click the Actions category, click Movie Clip Control,
and double-click stopDrag.
Flash automatically adds the onClipEvent handler.
11 Highlight the onClipEvent action in the Script pane and choose the Mouse up event.
Your code should look like the following code:
onClipEvent (mouseDown) {
startDrag("", true, 4, 70, 396, 273);
}
onClipEvent (mouseUp) {
stopDrag();
}
12 Choose Control > Test Movie and drag the movie clip to test the collision detection.
Whenever the bounding box of the car intersects the bounding box of the area, the status is true.
For more information about the hitTest method, see the online ActionScript Dictionary in the
Help menu.
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|