Skip to content

Instantly share code, notes, and snippets.

@adamcoulombe
Created April 5, 2012 14:59
Show Gist options
  • Save adamcoulombe/2311782 to your computer and use it in GitHub Desktop.
Save adamcoulombe/2311782 to your computer and use it in GitHub Desktop.
Simple radial proximity with AS3
//demo @ http://adamcoulombe.info/lab/as3/rangetest.swf
//download .fla http://adamcoulombe.info/lab/as3/rangetest.fla
range.visible=false;
stage.addEventListener(Event.ENTER_FRAME,tick);
function tick(e){
if(getDistance(mouseX,mouseY,source.x,source.y)<range.width/2){
range.visible=true;
}else{
range.visible=false;
}
}
function getDistance(x1:Number, y1:Number, x2:Number, y2:Number)
{
var dx:Number = x2 - x1;
var dy:Number = y2 - y1;
return Math.sqrt(dx*dx + dy*dy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment