When you create an image using newImage, it is added to the stage. When you want to remove it, either you need to have a reference to the image, or find it in the stage object. In the simple case you need the reference. If you have a local outside of the function, make sure it has a different name than the local inside the function (so that they are different references) but maybe you don’t need the local inside the function. If you are still having problems, can you post some code?
[import]uid: 54 topic_id: 1775 reply_id: 6686[/import]
I’m having a similar issue to amigoni. I just want to create a circle and then a physics body. When the circle get’s to a certain point, I want to remove it from stage/memory.
But when I run the code below, I get a runtime error, “attempt to compare nil with number”.
That circle is disappearing as soon as you created it since removeCircle is going to fire on the next frame update. It’s deleting the circle but too fast for you to see.
And unless you remove the enterframe event listener it’s going to keep firing and attempt to remove myCricle which has already been removed. That’s causing it to get an error when you compare myCircle.y with 300, since myCircle.y is nil - it was already removed.
Comment out your eventlistener line and replace it with: