问题
I'm creating an Javascript/HTML5-game in Flash CC.
I have an Info-screen with a button. This Infoscreen is a movieclip from the library with a linkname "CloseBtn". The following script is on frame 8 in this movieclip:
<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. But it does not work! Am I thinkg wrong when combining code with timeline?
回答1:
Problem solved!
The solution is the keyword "this" before the button when assigning the eventListener. Took me about 8 hours of frustrated code analysis to find out.
this.closeBtn.addEventListener("click", function (event)
{
this.gotoAndPlay(9);
});
来源:https://stackoverflow.com/questions/24557262/flash-cc-html5-ought-to-be-simple-gotoandplay