这是一个简单的“钥匙门解锁/没有钥匙门锁定”#39;布尔的东西,但每当我收集钥匙并尝试使用门时,它仍然无法打开并播放锁定的声音,我无法弄清楚原因。
var keyCollected: Boolean = false;
var doorOpen: Boolean = false;
keyclick_btn.buttonMode = true;
keyclick_btn.addEventListener(MouseEvent.CLICK, releasekey);
function releasekey(e: Event): void {
keymc.gotoAndPlay(1);
keyclick_btn.visible = false;
keymc.visible = true;
keyCollected == true;
}
doorhandle_btn.addEventListener(MouseEvent.CLICK, licklock);
function licklock(e: Event): void {
if (keyCollected == false) {
var lockSound: Lock = new Lock();
lockSound.play();
}
}
doorhandle_btn.addEventListener(MouseEvent.CLICK, open)
function open(e: Event): void {
if (doorOpen == false) { // if the door hasn't been opened yet
if (keyCollected == true) {
doorOpen = true;
trace("open");
doorOpenmc.visible = true;
doorOpenmc.gotoAndPlay(1);
}
}
}
答案 0 :(得分:0)
在releaseKey
函数中,您在以下语句中有额外的=
:
keyCollected == true;
其中只评估一个布尔值并且什么都不做。如果将其更改为keyCollected = true
,则open
函数中的if语句应评估为true。