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 ?

Cheers,

Terence
//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(globals.data.choice) {
	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
removeChild(yvesPort);
removeChild(catPort);
removeChild(antPort);

Open in new window

LVL 1
terencepiresAsked:
Who is Participating?
 
CyanBlueConnect With a Mentor Commented:
I guess I need a new pair of glasses...

Try this code in frame 2 instead...

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

Open in new window

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

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

for instance :

switch(globals.data.choice) {
       case "yves" : addChild(yvesPort); ...
0
 
terencepiresAuthor Commented:
working !
thanks !
0
All Courses

From novice to tech pro — start learning today.