Skip to main content
Participant
December 4, 2021
Question

HTML5 Canvas - object to remove self

  • December 4, 2021
  • 1 reply
  • 152 views

Hi everyone, newbie question:

 

I have a scipt that imports a movieclip from the library. That movieclip contains a button, and when I press that button I need it to remove the movieclip that contains it.

 

Any idea what code can achieve that?

 

Many thanks in advance!

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 5, 2021

    Hi.

     

    Here is a suggestion:

    var mc = new lib.YourLibraryLinkage();
    
    this.addChild(mc);
    
    mc.yourButton.on("click", function(e)
    {
    	e.currentTarget.parent.parent.removeChild(e.currentTarget.parent);
    }, null, true);

     

    I hope this helps.

     

    Regards,

    JC

    Participant
    December 5, 2021

    Hey JS, thanks so much for your reply. The one thing I don't really get is how the hierarchy works for nested movieclips/buttons.

     

    I undertand there is some kind of this.mc1.mc2.bt1 logic to access a button from stage, but what if you wanted that button to access mc2's timeline?

     

    Thanks again!