简体   繁体   English

Flash CC HTML5应该是简单的gotoAndPlay

[英]Flash CC HTML5 ought to be simple gotoAndPlay

I'm creating an Javascript/HTML5-game in Flash CC. 我正在Flash CC中创建Javascript / HTML5游戏。

I have an Info-screen with a button. 我有一个带有按钮的信息屏幕。 This Infoscreen is a movieclip from the library with a linkname "CloseBtn". 此信息屏幕是来自库的影片剪辑,其链接名为“ CloseBtn”。 The following script is on frame 8 in this movieclip: 以下脚本在此动画片段的第8帧上:

<code>
this.stop();
var closeBtn=new lib.CloseBtn();
closeBtn.x=130;
closeBtn.y=150;
closeBtn.stop();
this.addChild(closeBtn);
closeBtn.addEventListener("click", function (event)
{
        this.gotoAndPlay(9);    
});
</code>

As you probably have guessed this should gotoAndPlay frame 9 in the InfoScreen when the button is clicked. 您可能已经猜到,单击按钮后,这应该转到InfoScreen中的第9帧。 But it does not work! 但这行不通! Am I thinkg wrong when combining code with timeline? 将代码与时间轴结合在一起时,我认为是错误的吗?

Problem solved! 问题解决了!

The solution is the keyword "this" before the button when assigning the eventListener. 解决方案是在分配eventListener时,在按钮前添加关键字“ this”。 Took me about 8 hours of frustrated code analysis to find out. 花了大约8个小时对我进行了沮丧的代码分析,以找出答案。

    this.closeBtn.addEventListener("click", function (event)
    {
        this.gotoAndPlay(9);    
    });

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

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