First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Art Bowles | Website: http://www.launchfire.com

Flash MX hitTest method


Movieclip.hitTest(x, y, shapeflag)
Movieclip.hitTest(target) Note on Usage
It got me confused in the beginning, so just to clarify, if you want to test if object A hits object B (ie does the rock hit the window) you have to write it as follows

If (window.hitTest(rock));

If performing a simple hit test with target, it will still work if written reversed, but it’s not correct.


I wrote this tutorial after running into problems porting over one of my action games into
Flash MX. It seemed the hitTest function, at least how I had written it, was no longer valid. After some research I realized, MX does not accept eval on the left side of an argument, instead prefering to use brackets []. In fact, MX suggest any time you want to evaluate an expression, you place is inside []. To learn more read up on the symbol [] (array access) Eval (“A” + i); this[“A” + i]


My action game was a shoot the puck on the goalie/targets type game, in which I had to determine if the puck hit the target (easy) or the goalie (a little more difficult because of legs and arms). The target was a picture a circle inside a movie clip, and the goalie was basically the same. The trouble with the goalie was if it hit between his legs, that had to be a goal. So using the target argument was out, I needed to use x,y, and shapeflag arguments. In this tutorial, I am going to test using both target and shapeflag, mainly because I wanted to know what is possible in a variety of situations.

All the code for determining hits resides within the ActionPuck Movie Clip, on frame 6. Commented out are all the examples listed below.

Testing using the Target Argument

The ‘help’ file in MX says the target usually represents a button or text-entry field. Well, maybe, but I’ve only ever used it to reference another movie clip, so that’s what I’ll test against in this tutorial. On a basic level, testing for a hit using target is the same in MX or Flash 5, however, that’s about where the similarities end.

hit1 = _root.TestGoalie.hitTest("_root.ActionPuck"); //
F5 and MX compatible

if (hit1)
trace ("hit1");
if ( _root.TestGoalie.hitTest("_root.ActionPuck")) {
trace ("hit1");

» Level Intermediate

Added: 2003-01-14
Rating: 7 Votes: 28
(10 being the highest)
» Author
An ex network admin who found solace in lines of code.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.