Skip to main content
Participant
June 4, 2024
Question

removeChild fails after convert layer into symbols

  • June 4, 2024
  • 1 reply
  • 115 views

Hi everyone,

 

Here I have a symbol(symbol1), it contains 3 layers

  • layer1, named 'as', it contains only one line on frame 100

 

removeChild(this)​

 

  • layer2, is a layer contains pic1
  • layer3, is a layer contains pic2

 

It goes all well. Until I changed layer2 and layer 3 into symbol2 and symbol3.

After layer2, layer3 are changed into symbols.

Symbol2 is put back on layer2, and Symbol3 is on layer3.

Everything keeps same, just all key frames are now contained in individual symbols.

 

And then,  code on layer1 raises error.  IT DOES NOT WORK NOW.

Error #1034: Type Coercion failed: flash.display::Stage@5e12d25d0d1  cannot convert to flash.display.MovieClip

 

I've also tried 

 

removeChild(this.symbol2)

 

to remove one layer directly. It still fails

ArgumentError: Error #2025: The provided DisplayObject must be a child of the caller.

 

Trace(symbol2.parent)

 

The result of the Trace statement above is: Parent of symbol2: [object symbol1]

So symbol2, is indeed a child of symbol1.

 

Any ideas? Again it works again if I put all key frames back on layer 2 and 3. But I just want to make them individual symbols so it'd be easier to reuse.

 

Thanks.

 

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    June 4, 2024

    you should be using instance names.

     

    whatever you want to remove use, trace(this) or trace(this.name), to confirm you have dealing with the correct object.  then you can use:

     

    whatever.parent.removeChild(whatever)