【发布时间】:2020-10-28 02:43:46
【问题描述】:
在 Adobe Animate (HTML5 Canvas) 中,我需要检查是否已单击两个按钮并前进到第二帧,以及是否都显示了影片剪辑。
我是编程新手,甚至不知道如何开始。我想过使用 eventListner 或 if/else 语句。没有得到任何工作。任何帮助将不胜感激。
【问题讨论】:
标签: html canvas jquery-animate adobe easeljs
在 Adobe Animate (HTML5 Canvas) 中,我需要检查是否已单击两个按钮并前进到第二帧,以及是否都显示了影片剪辑。
我是编程新手,甚至不知道如何开始。我想过使用 eventListner 或 if/else 语句。没有得到任何工作。任何帮助将不胜感激。
【问题讨论】:
标签: html canvas jquery-animate adobe easeljs
我会尝试根据我的知识回答这个问题,希望它足够简单易懂,但我确信可能有更好的方法来编写这些函数。
buttonClick(evt) 允许打开和关闭按钮,假设影片剪辑的第 0 帧处理按钮的关闭状态,而第 1 帧处理打开状态。然后在每次点击时调用一个函数来检查按钮的状态。
checkButtonStates() 是一个条件语句,它只检查按钮的当前帧,如果两者都为 1,则显示并播放影片剪辑。
const button1 = stage.children[0].button1_mc;
const button2 = stage.children[0].button2_mc;
const movieclip3 = stage.children[0].movieclip3_mc;
button1.addEventListener("click", buttonClick);
button2.addeventListener("click", buttonClick);
function buttonClick(evt) {
button = evt.currentTarget;
// check current frame of button and changes frame
if (button.currentFrame == 0){
button.gotoAndStop(1);
} else {
button.gotoAndStop(0);
}
checkButtonStates();
}
function checkButtonStates(){
// if both buttons have been clicked hide buttons and play movie
if (button1.currentFrame == 1 && button2.currentFrame == 1){
showButtons(false);
showAndPlayMovie(true);
}
}
// buttons visible property set by passed parameter
function showButtons(bool){
button1.visible = bool;
button2.visible = bool;
}
// changes visible property of movie by passed parameter. If movie is visible the movie is played.
function showAndPlayMovie(bool){
movieclip3.visible = bool;
if (movieclip3.visible == true){
movieclip3.play();
}
}
【讨论】: