Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-25-2011, 12:26 AM   #1
Registered User
Join Date: May 2011
Location: North Carolina
Posts: 5
Default [AS3] Show object under certain conditions?

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:

ActionScript Code:
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);             }             else             {                 removeChild(rayBeam);             }             if (player.hitTestObject(blueTarget))             {                 trace("hit by a target");             }

And here is the closeToBlue function:

ActionScript Code:
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;             addChild(rayBeam);             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.
at flash.display:isplayObjectContainer/removeChild()
at classes::engine/loop()

Any suggestions are greatly appreciated. Thank you in advance for any and all help.
valadus is offline   Reply With Quote
Old 05-25-2011, 05:44 AM   #2
Senior Member
Join Date: Mar 2011
Posts: 152

check to see if rayBeam is there to be removed first
holysocks is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 09:01 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.