removeChild issue

Hi there,

i'm trying to remove a child from the stage but that won't work...

In the code below i retrieve a string from a global variable, and then instantiate the right movieclip.
Then in frame 2 i'm trying to remove them from stage, but no can do...

i get an error message :
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

can someone tell me what's wrong ?


//frame 1

//creating the variables
var yvesPort:yvesportrait = new yvesportrait(); 
var antPort:portraitantoine = new portraitantoine(); 
var catPort:catherineportrait = new catherineportrait(); 

//adding the right movieclip
switch( {
	case "yves" : addChild(yvesPort); yvesPort.x = 524.95; yvesPort.y = 337; break;
	case "antoine" : addChild(antPort); antPort.x = 524.95; antPort.y = 337; break;
	case "catherine" : addChild(catPort); catPort.x = 524.95; catPort.y = 337; break;

//frame 2

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Where are you adding them to the stage???  I don't see addChild() lines???

terencepiresAuthor Commented:
read carefully, addChild is the first instruction of each "case" line

for instance :

switch( {
       case "yves" : addChild(yvesPort); ...
I guess I need a new pair of glasses...

Try this code in frame 2 instead...

if (yvesPort && contains(yvesPort)) removeChild(yvesPort);
if (catPort && contains(catPort)) removeChild(catPort);
if (antPort && contains(antPort)) removeChild(antPort);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
terencepiresAuthor Commented:
working !
thanks !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.