I am making a game where once the player is close enough to an object, a "ray" appears, increasing the players score so long as they are close enough. I designed the ray animation and brought it over to my game's engine successfully, but now I am having trouble only showing it when the player is close enough.
This is the code I currently have:
blueXDist = Math.round(blueTarget.x - player.x);
blueYDist = Math.round(blueTarget.y - player.y);
blueDistance = Math.round(Math.sqrt((blueXDist * blueXDist) + (blueYDist * blueYDist)));
var rayBeam:DisplayObject = new ray(blueDistance);
if (blueDistance < 100)
blueHitTimes += 1;
trace("blue hits: " + blueHitTimes);
closeToBlue(blueYDist, blueXDist, rayBeam);
trace("hit by a target");
And here is the closeToBlue function:
public function closeToBlue(yDistance:Number, xDistance:Number, rayBeam)
var distance:Number = xDistance - yDistance;
var radian:Number = Math.atan2(yDistance,xDistance);
var rotationAmount = radian * 180 / Math.PI;
rayBeam.x = player.x + 10;
rayBeam.y = player.y + 10;
rayBeam.rotation = radian * 180 / Math.PI;
And this code returns this error in the output window at runtime:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
Any suggestions are greatly appreciated. Thank you in advance for any and all help.