Hello, I am coding a game with an inventory and I am using addChild to move the item clicked on into the inventory. This works fine, however when I move forward on the time line and then return to the same frame, the item remains where it was in addition to being in the inventory. My understanding is that the addChild automatically removes the child from the stage when it puts it into another MC, however this is not what's happening. I've tried removeChild however as the child has initially been removed, it throws up an error message. Here's code for the function triggered by the eventListener:
addChild doesn't necessarily remove anything. it can re-parent a displayobject and change the object's depth.
for example, if inventory_mc is not on the stage, adding a stage object (eg, deserflower_mc) to inventory_mc will remove desertflower_mc from the stage.
but when you return to a keyframe where that object is instantiated, it will have all the properties (including parent, position etc) it originally had before your code changed its properties. there's nothing you can do to prevent that.
you could work around it by maintaining a database (eg, an abstract object or even a sharedobject), but when you mix timeline and code displayobject manipulation you're making things complicated. it would be easier to use code to add all your potential inventory items.
eg, on the frame that instantiates desertflower_mc, remove it from the stage and in your library assign it a class (eg, Desertflower). you could then use code to instantiate it: