Agro range on following code
A couple weeks ago, I was assissted by kglad in recieving a code that makes enemy MC's follow a player mc controlled with the arrow keys, and food MC that moves away from the player. the code for the food is as follows:
var runBallA:Array = [food1MC,food2MC,food3MC];
for(var i:Number=0;i < runBallA.length;i++){
runBallA.speed = -3;
}
runBallI = setInterval(runBallF,40);
function runBallF(){
for(var i:Number=0;i < runBallA.length;i++){
var ang:Number = Math.atan2(runBallA._y-player._y,runBallA._x-player._x);
runBallA._x += Math.cos(Math.PI+ang)*runBallA.speed;
runBallA._y += Math.sin(Math.PI+ang)*runBallA.speed;
}
updateAfterEvent();
}
my question is how do i put an agro range on this code so that the foodMC moves away from the player only when the player is within (i.e.) 100 pixels?