1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

ActionScripting Basics: Collision Test Using hitTest


Now I’m ready to start confusing you. Follow along closely, because every step after this is going to be something new that we haven’t covered in any previous lessons.

The first we’re going to cover is an Actions->Movie Clip Control->onClipEvent. These commands are event commands that trigger actions defined for that specific instance of a movie clip—basically telling it when to do a specific thing based on a specific condition. That specific condition is called a movieEvent, and is the parameter placed inside the parentheses after the onClipEvent string. A movieEvent may be load, meaning that whatever is in the brackets after the defined event will happen when the movie loads, or mouseMove, meaning that the action is triggered by any motion of the mouse—or any number of others.

For this instance, we’re going to use enterFrame:

onClipEvent (enterFrame) {

This means that whenever the movie clip enters a new frame of the timeline, it will repeatedly perform the actions defined inside the { } brackets at each frame. In our case, we want to tell it to check and see if this movie clip (projectile) has collided with another movie clip (target).

©2014 About.com. All rights reserved.