Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 2

_droptarget vs hitTest for detecting collisions

Download the FLA file


If you drag the blue square towards the orange square, you'll see that hitTest detects a collision as soon as the two squares touch. Whereas _droptarget doesn't detect a collision until the two objects are significantly overlapping. _droptarget is good for Flash jigsaw puzzles, where you want it to 'count' only when a puzzle piece is almost completely where it should be. It's also good for dragging things into a trashcan, etc.

So that the text boxes can continuously show the current value of _droptarget and hitTest as you drag the blue square, the code includes use of the setInterval command, which in this case calls a function every tenth of a second to update the text boxes.

Note that if you drag the blue square over the text boxes, _droptarget displays the instance names of the text boxes.

stop();

movable_square_mc.onPress = function()  {
	startDrag(this, true);
	setInterval(showDropTarget,100);
};

function showDropTarget() {
	textbox1_txt.text = movable_square_mc._droptarget;
	textbox2_txt.text = movable_square_mc.hitTest(square_mc); 
}

movable_square_mc.onRelease = function() {
	stopDrag();	
};


 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM