【发布时间】:2014-11-01 19:32:01
【问题描述】:
我有一些代码将“返回”按钮添加到具有自己代码的阶段,单击它会删除按钮并将用户带回标题屏幕。但是,当“返回”按钮重新引入舞台时,它的侦听器都不起作用。
public class BACK extends SimpleButton {
public function BACK() {
// constructor code
trace('back button on stage');
addEventListener(Event.ADDED_TO_STAGE, startUp);
}
function startUp(ev:Event): void{
addEventListener(MouseEvent.CLICK, gotoTitle);
addEventListener(Event.REMOVED_FROM_STAGE, backBtnCleanUp);
}
function gotoTitle(ev:MouseEvent): void{
trace('gototitle called');
MovieClip(root).gotoTitle();
}
function backBtnCleanUp(ev:Event): void{
trace('back button cleanup called');
removeEventListener(Event.ADDED_TO_STAGE, startUp);
removeEventListener(MouseEvent.CLICK, gotoTitle);
removeEventListener(Event.REMOVED_FROM_STAGE, backBtnCleanUp);
}
}
trace 函数在首次添加到阶段时执行,但在移除后再次添加时不执行。这是添加和删除它的代码(来自 Main)。
function gotoHelp(): void{ // transitions to the help screen
cleanTitle();
addChild(helpBG);
addChild(backBtn);
backBtn.x = 550;
backBtn.y = 200;
}
function gotoTitle(): void{ //goes to the title screen
trace('going to title');
removeChild(backBtn);
removeChild(helpBG);
titleStartUp();
}
【问题讨论】:
-
你实际上是在哪里构造一个新的
Back按钮实例? -
在 gotoHelp 函数中,它被命名为“backBtn”。它链接到 BACK 类。还是我不理解“构造”一词在这种情况下的含义?
标签: actionscript-3 event-listener