Web
Article

Flash Script – Simple Hit Detection

By Georgina Laidlaw


Download the sample files here.

1. Create a new movie with width=400 and height=300.

2. Create two rectangles, one that’s red and one that’s blue.

3. Convert the first red rectangle into a movieclip, and name it "red" in the instance box.

4. Convert the second blue rectangle into a movieclip and name it "blue" in the instance box.

5. Create a text field, and name it "information".

6. Create a new layer above the current layer, and name it "actions".

7. Insert the following action into the first key frame:

if (circle.hittest(red))  
{  
information = "The Circle Hit Red";  
}  
if (circle.hittest(blue))  
{  
information = "The Circle Hit Blue";  
}

8. In the second frame, enter this action:

gotoAndPlay (1); 

9. Now, simply press ctrl+enter to test the movie.

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in Front-end, once a week, for free.