Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

addChild removes an object?

Status
Not open for further replies.

reaktor

IS-IT--Management
Nov 19, 2007
2
SI
var bitmap:Bitmap = new Bitmap();
bitmap = spritesArray[selectedIndex].getChildAt(0) as Bitmap; //first child is the loaded Bitmap

trace("NUMBER BEFORE: " + spritesArray[selectedIndex].numChildren);
imageHolder.addChild(bitmap);
trace("NUMBER AFTER: " + spritesArray[selectedIndex].numChildren);

---------
OUTPUT:

NUMBER BEFORE: 1
NUMBER AFTER: 0

---------

Why?

I'm trying to use spritesArray as container of Sprites, on which I put loaded Bitmaps - as box of photos in a frame.
When I want to add the Bitmap to imageHolder, it obviously gets deleted from spritesArray. Isn't that only a reference. I get it that any Object can only be a child of oneObject (if they are visible), but spritesArray is not added as child anywhere - so Bitmaps inside it are not visible anywhere else. Or am I missing something big?

What is a solution, to copy it back after it is switched? To duplicate it? Bummer, really.

Thanks for help in advance.
 
From the doc:
If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.
This applies to all display object containers whether they are added as children or not.

One solution is make your "spritesArray" an Array. Arrays are not DisplayObjectContainers.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top