简体   繁体   English

HTML5 canvas(Animate CC)使用按钮从舞台上删除动画片段

[英]HTML5 canvas (Animate CC) remove movieclip from stage with button

please help, I have spent a whole morning trying to figure this out and have failed miserably. 请帮忙,我花了整整一个上午的时间来解决这个问题,但失败了。

I am trying to update an old swf file into a new html canvas. 我正在尝试将旧的swf文件更新为新的html画布。

So far I have updated everything including loading my desired movieclip Image_1 onto the stage into var "fl_MyInstance" this is loaded through button_1 via the following code.. 到目前为止,我已经更新了所有内容,包括将所需的movieclip Image_1加载到舞台上的变量“ fl_MyInstance”中,并通过以下代码通过button_1进行加载。


this.button_1.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler()
{
    var fl_MyInstance = new lib.Image_1();
    fl_MyInstance.x = 364.70;      
    fl_MyInstance.y = 199.30;       
    this.addChild(fl_MyInstance);

}

When this movieclip is on stage it has a button within that is labelled close1 and I have tried many many codes to try and close it.... but it just isn't working. 当此动画片段在舞台上时,其中有一个标记为close1的按钮,我尝试了很多代码尝试将其关闭.....但它无法正常工作。

The latest code I tried is.. 我尝试的最新代码是..

this.close1.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler()
{
  stage.removeChild( fl_MyInstance );
}

Please help, I arrived at this as I know it perhaps needs to target a parent or reference the stage or root or something, but everything tried does nothing. 请帮忙,我到达了这个位置,因为我知道它可能需要以父母为对象或引用阶段或根目录或其他东西,但是尝试的一切都无济于事。 I don't even mind clearing all children if necessary. 如果有必要,我什至不介意清理所有孩子。

Hopefully somebody can help. 希望有人可以提供帮助。

Mark 标记

Your problem here is to do with scope. 您的问题在于范围。 Try the following in a new file. 在新文件中尝试以下操作。 Draw two movieclips on the stage and name them buttonAdd and buttonRemove. 在舞台上绘制两个影片剪辑,并将其命名为buttonAdd和buttonRemove。 In your library have a movie clip named Rectangle. 在您的媒体库中,有一个名为Rectangle的影片剪辑。 Now add the following code: 现在添加以下代码:

var that = this;
this.buttonAdd.addEventListener("click", addFromLibrary);
this.buttonRemove.addEventListener("click", removeClip);

function addFromLibrary(e)
{   
    window.myRectangle = stage.addChild(new lib.Rectangle());
}

function removeClip(e){
    stage.removeChild(myRectangle);
}

This should work but there are probably more elegant ways of achieving this. 这应该可行,但是可能有更优雅的方法可以实现这一目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM