Copy link to clipboard
Copied
I'm creating a 2D game and I was creating an event for when my character touches a gem, it 'collects' the gem and the image is removed. However when playing the game and the character touches the gem the game crashes and I am presented with the error.
This is the code that I added:
public function Collect():void
{
if (FireBoy.hitTestObject(Green))
{
Green.parent.removeChild(Green);
}
}
I have checked where the error is coming from and apparently the error lies with the line Green.parent.removeChild(Green);
What do I need to do to fix the error and to allow my character to still collect the gem?
What is driving the Collect function to execute? If it is involved in some form of EnterFrame processing it might be a case where you are still trying to remove Green after it has already been removed. Try putting a trace just before that line to see what the status of Green is before you remove it.
Copy link to clipboard
Copied
What is driving the Collect function to execute? If it is involved in some form of EnterFrame processing it might be a case where you are still trying to remove Green after it has already been removed. Try putting a trace just before that line to see what the status of Green is before you remove it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now