有人可以帮我处理计时器和声音事件吗?
Can someone help me with timer and sound events?
所以我正在尝试创建一个标题屏幕,该屏幕显示图像并在 5 秒后消失,而不是程序启动后立即播放歌曲。这首歌将贯穿整个游戏。
public function TitleScreen(){//adds a Title Screen
var tsBackground:tsBack= new tsBack();
tsBackground.x= -22
tsBackground.width=650
tsBackground.height=450
addChild(tsBackground);
var mainTheme:tsTheme = new tsTheme();
mainTheme.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:TimerEvent){
mainTheme.play();
}
var counter = 0;
var myTimer:Timer = new Timer(5000);
myTimer.addEventListener(TimerEvent.TIMER, TimerFunction)
function TimerFunction(event:TimerEvent){
counter++
removeChild(tsBackground);
AddStuff();
}
myTimer.start();
/*if (myTimer >= 5000) {
myTimer.stop();
}*/
}//end of TitleScreen
我注释掉了确定它是否停止的 if 语句,因为我收到此错误:
1176: Comparison between a value with static type flash.utils:Timer and a possibly unrelated type int.
我遇到的第二个问题是 mainTheme.play(); 时歌曲没有播放;被调用,我知道我正确地做了链接。
有人可以帮忙吗?
错误告诉您正在尝试将 myTimer
对象(类型 Timer
)与整数 (5000) 进行比较。这就像试图问 "Which is greater: the number 3 or this lamp?"。我想你的意思是比较你的 counter
变量,但即使那样也不会像你想要的那样工作。
您的 TimerFunction
是 运行 在计时器归零时触发的功能。所以没有必要做那个比较。您已经知道 5 秒何时结束,因为该函数将 运行。所以你可以在那里停止计时器。您可能还想删除那里的事件侦听器:
function TimerFunction(event:TimerEvent){
removeChild(tsBackground);
AddStuff();
myTimer.stop();
myTimer.removeEventListener(TimerEvent.TIMER, TimerFunction);
mainTheme.play();
}
所以我正在尝试创建一个标题屏幕,该屏幕显示图像并在 5 秒后消失,而不是程序启动后立即播放歌曲。这首歌将贯穿整个游戏。
public function TitleScreen(){//adds a Title Screen
var tsBackground:tsBack= new tsBack();
tsBackground.x= -22
tsBackground.width=650
tsBackground.height=450
addChild(tsBackground);
var mainTheme:tsTheme = new tsTheme();
mainTheme.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:TimerEvent){
mainTheme.play();
}
var counter = 0;
var myTimer:Timer = new Timer(5000);
myTimer.addEventListener(TimerEvent.TIMER, TimerFunction)
function TimerFunction(event:TimerEvent){
counter++
removeChild(tsBackground);
AddStuff();
}
myTimer.start();
/*if (myTimer >= 5000) {
myTimer.stop();
}*/
}//end of TitleScreen
我注释掉了确定它是否停止的 if 语句,因为我收到此错误:
1176: Comparison between a value with static type flash.utils:Timer and a possibly unrelated type int.
我遇到的第二个问题是 mainTheme.play(); 时歌曲没有播放;被调用,我知道我正确地做了链接。
有人可以帮忙吗?
错误告诉您正在尝试将 myTimer
对象(类型 Timer
)与整数 (5000) 进行比较。这就像试图问 "Which is greater: the number 3 or this lamp?"。我想你的意思是比较你的 counter
变量,但即使那样也不会像你想要的那样工作。
您的 TimerFunction
是 运行 在计时器归零时触发的功能。所以没有必要做那个比较。您已经知道 5 秒何时结束,因为该函数将 运行。所以你可以在那里停止计时器。您可能还想删除那里的事件侦听器:
function TimerFunction(event:TimerEvent){
removeChild(tsBackground);
AddStuff();
myTimer.stop();
myTimer.removeEventListener(TimerEvent.TIMER, TimerFunction);
mainTheme.play();
}