views:

40

answers:

2

Hey guys, got a problem with my pages in flash. So i created 5 pages, each of which contains several movie clips (text, graphics, forms, etc). There is one specific page however that contains autogenerated content via. sprites. If i happen to land on this page, the sprites will appear, but when i transition to another page, they are still there except for the non-sprite stuff (disappear). Im ripping my hair out on this one, i managed to get a few of the sprites to remove but some are still appearing. Below shows the layout of the one thats not being removed;

var container:Sprite = new Sprite();

//loop places several "item" in this container sprite and a scroll bar
var item:myItem = new myItem();
var sb:customScrollBar = new customScrollBar();

container.addChild(item);
container.addChild(sb);

So we are now on this page where container and items are generated, i then click a button to move to say the home page and the container still stays there.

Here is what i tried:

removeChild(container); //nothing, this was called from another keyframe where the container was not generated from
stage.removeChild(container); //nothing

Here are the errors. ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

Note* I also have several buttons that were also generated NOT inside the container like below and they worked when i ran removeChild(button1) so i dont know why the container one is not working.

FLA (cs4) http://www.4shared.com/file/2swJjnNm/mevame.html

Preview http://bodog-bonuses.com/mevame/

A: 

Something similar happened to me before which I solved by doing the following. It depends on how your instances of container I created and therefore recognized by the parent.

var container:Sprite = new Sprite();
container.name = "container";

//------- later
var child:DisplayObject = getChildByName("container");
removeChild(child);

If you need to remove all children you could also do this

while( this.numChildrem > 0 )
     this.removeChildAt(0);
PatrickS
A: 

This is likely caused by that fact that with a timeline animation, any given keyframe may contain an object however with each keyframed list of actions, you lose scope on the previous keyframe's contents. So if you call remove child before you cross a new timeline keyframe, you will likely be able to successfully call removeChild on the container.

Otherwise, you can utilize Patrick's suggestion, which will definitely find the object on the stage and remove it, though it is one of the more inefficient means of retrieving an object from the display list.

Tegeril