A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5828 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


Random Links | Add your own Flash Related Links
Flash Tutorials 1280 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting

Categories Advanced HitTest in Flash MX
Author: Art Bowles | Website: www.launchfire.com |

 
Page 1
1 2 3 next»

Flash MX hitTest method

Usage

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.

Background

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]

Overview

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");
}

1 2 3 next»

» Level Intermediate

Added: : 2003-01-14
Rating: 6.62 Votes: 26
Hits: 11
» Author
An ex network admin who found solace in lines of code.
» Download
Download the files used in this tutorial.
Download (42 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs