Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 2

Detecting collisions using _droptarget

Download the FLA file

This Flash movie demonstrates one way to detect collisions between two objects on the stage using ActionScript 2, using the "_droptarget" property. For more on this technique and to compare it to the "hitTest" technique of detecting collisions, see _droptarget vs hitTest.
Below is the code for frame 1 of 3;

stop();

start_btn.onRelease = function() {
  nextFrame();	
}

Below is the code for frame 2 of 3.

stop();

garbage_mc.onPress = function()  {
	startDrag(this, true);
};

garbage_mc.onRelease = function() {
	stopDrag();
	if (this._droptarget == "/trash_can_mc") {
		setProperty(this, _visible, false);
		thank_you_mc._alpha = 100;
		nextFrame();
	}
	else if (this._droptarget == "/mr_muncher_mc") {
		setProperty(this, _visible, false);
		burp_mc._alpha = 100;
		nextFrame();
	}
	
};

Below is the code for frame 3 of 3:

stop();

again_btn.onRelease = function() {
	setProperty(garbage_mc, _visible, true);
	garbage_mc._x = 270;
	garbage_mc._y = 150;
	burp_mc._alpha = 0;	
	thank_you_mc._alpha = 0;
	prevFrame();
}


 
« Return


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