Animation

  1. Home
  2. Computing & Technology
  3. Animation

ActionScripting Basics: Collision Test Using hitTest

By Adrien-Luc Sanders, About.com

7 of 10

To start off, we’re going to define an if condition. If/else statements generally take the format of “if x is present, then perform y; else, perform z” in most logical operators present throughout mathematics and any number of programming languages. Flash is no different; you just have to watch and make sure that you’re using the right syntax.

What we basically want to say is “if collision is true, then play the target movie clip”, without any else needed in this simple instance. So with the onClipEvent selected to make sure our if statement will appear inside it, then drill down to Actions->Conditions/Loops->if and double-click to insert it. Your code will appear as follows:

onClipEvent (enterFrame) {
if (not set yet) {
}
}

The red highlight is telling us that we need to insert a parameter inside those parentheses or this script won’t work at all. But before we do that, let’s talk about what we just told Flash in basic terms:

”Every time that the current movie clip enters a new frame, check to see if (as yet undefined condition) takes place. If it does, then perform the as yet undefined action inside the {} brackets after the opening of the if statement.” We’re nesting conditions at this point, basically creating a chain to narrowly control our movie clip’s behavior by placing functions inside of these conditions so they only take place when specific criteria are met.

Explore Animation

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Animation

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. ActionScripting Basics: Collision Test Using hitTest

©2009 About.com, a part of The New York Times Company.

All rights reserved.