1. Computing & Technology

Discuss in my forum

ActionScripting Basics: Collision Test Using hitTest

By , About.com Guide

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.

©2012 About.com. All rights reserved.

A part of The New York Times Company.