ActionScript: Get distance between 2 MovieClips

Si on veut la distance en pixels entre 2 objets graphiques il suffit d’utiliser le théorème de Pythagore en ActionScript :).

c² = a² + b²

[swf:/wp-content/uploads/2010/11/Get_Distance.swf 550 400]

Télécharger les codes sources : Get_Distance.zip

function getDistance(pObj1:MovieClip,pObj2:MovieClip):Number {
	var distX:Number = pObj1.x - pObj2.x;
	var distY:Number = pObj1.y - pObj2.y;
	return Math.sqrt(distX * distX + distY * distY);
}