45 秒間生き続けなければならないゲームがありますが、死ぬとシーン 4 に移動し、クリックしてシーン 3 を再開できます (ここで死なないようにします)。私の問題はタイマーにあります。シーン 3 でタイマーを宣言しますが、シーン 1 で開始するように見えます。また、私が死ぬとき、タイマーは再始動または停止しないため、何度も何度も死ぬ可能性があります。合計 45 秒、自動的に勝ちます。このエラーが発生している場所がわからないので、すべてのコードを貼り付けます。//シーン 1
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,Intro);
function Intro(e:Event)
{
var mySound:Sound = new E();
mySound.play();
Asteroid1.y = Asteroid1.y + 20;
Asteroid2.y = Asteroid2.y + 24;
Asteroid3.y = Asteroid3.y + 16;
Asteroid4.y = Asteroid4.y + 28;
Asteroid5.y = Asteroid5.y + 17
Asteroid6.y = Asteroid5.y + 22
Asteroid1.x = Asteroid1.x + 19;
Asteroid2.x = Asteroid2.x + 18;
Asteroid3.x = Asteroid3.x + 14;
Asteroid4.x = Asteroid4.x + 17;
Asteroid5.x = Asteroid5.x + 21
Asteroid6.x = Asteroid6.x + 20
if(Asteroid1.y > 768){
Asteroid1.y = -40;
}
if(Asteroid2.y > 768){
Asteroid2.y = -40;
}
if(Asteroid2.x > 1024){
Asteroid2.x = -40;
}
if (Asteroid1.x > 1024){
Asteroid1.x = -40
}
if(Asteroid3.x > 1024){
Asteroid3.x = -20;
}
if (Asteroid3.y > 768){
Asteroid3.y = -20;
}
if (Asteroid4.y > 768){
Asteroid4.y = -20;
}
if(Asteroid4.x > 1024){
Asteroid4.x = -20;
}
if (Asteroid5.y > 768) {
Asteroid5.y = -30;
}
if (Asteroid5.x > 1024) {
Asteroid5.x = -40;
}
if (Asteroid6.y > 768){
Asteroid6.y = -30;
}
if (Asteroid6.x > 1024) {
Asteroid6.x = -30;
}
}
//Scene 2
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,IntroS2);
function IntroS2(e:Event) {
Asteroid5.y = Asteroid5.y + 20;
Asteroid6.y = Asteroid6.y + 18;
Asteroid7.y = Asteroid7.y + 16;
Asteroid8.y = Asteroid8.y + 22;
Asteroid9B.y = Asteroid9B.y + 17
Asteroid5.x = Asteroid5.x + 20;
Asteroid6.x = Asteroid6.x + 22;
Asteroid7.x = Asteroid7.x + 14;
Asteroid8.x = Asteroid8.x + 18;
Asteroid9B.x = Asteroid9B.x + 16
if (Asteroid5.y > 768) {
Asteroid5.y = -40;
}
if (Asteroid6.y > 768) {
Asteroid6.y = -40;
}
if (Asteroid5.x > 1024) {
Asteroid5.x = -40;
}
if (Asteroid6.x > 1024) {
Asteroid6.x = -20;
}
if (Asteroid7.x > 1024) {
Asteroid7.x = -20;
}
if (Asteroid7.y > 768) {
Asteroid7.y = -20;
}
if (Asteroid8.y > 768) {
Asteroid8.y = -20;
}
if (Asteroid8.x > 1024) {
Asteroid8.x = -20;
}
if (Asteroid9B.x > 1024){
Asteroid9B.x = -30;
}
if (Asteroid9B.Y >768){
Asteroid9B.y = -20;
}
}
//Scene 2 last frame
stop();
stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown);
function _onStageMouseDown(e:MouseEvent):void
{
removeEventListener(Event.ENTER_FRAME,IntroS2);
gotoAndStop(1, "Scene 5");
}
//Scene 3
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,ms3);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
myTimer.addEventListener(TimerEvent.TIMER, handleTimerTick);
stage.removeEventListener(MouseEvent.CLICK, _onStageMouseDown1);
stage.removeEventListener(MouseEvent.CLICK, _onStageMouseDown);
Mouse.hide();
//TIMER
var myTimer:Timer = new Timer(1000, 1); // 1 second
myTimer.addEventListener(TimerEvent.TIMER, onEnterFrame);
myTimer.start();
//TIMER
function ms3(e:Event){
Mouse.hide();
Planet3.y = mouseY;
Planet3.x = mouseX;
Asteroid9.x = Asteroid9.x + 26;
Asteroid9.y = Asteroid9.y + 21;
if (Asteroid9.x > 1024){
Asteroid9.x = -40
}
if (Asteroid9.y > 768){
Asteroid9.y = -40
}
Asteroid10.x = Asteroid10.x + 22;
Asteroid10.y = Asteroid10.y + 23;
if (Asteroid10.x > 1024){
Asteroid10.x = -40
}
if (Asteroid10.y > 768){
Asteroid10.y = -40
}
Asteroid11.x = Asteroid11.x + 18;
Asteroid11.y = Asteroid11.y + 21;
if (Asteroid11.x > 1024){
Asteroid11.x = -40
}
if (Asteroid11.y > 768){
Asteroid11.y = -40
}
Asteroid12.x = Asteroid12.x + 24;
Asteroid12.y = Asteroid12.y + 22;
if (Asteroid12.x > 1024){
Asteroid12.x = -40
}
if (Asteroid12.y > 768){
Asteroid12.y = -40
}
// Hit Test
if(Planet3.hitTestObject(Asteroid9)||
Planet3.hitTestObject(Asteroid10)||
Planet3.hitTestObject(Asteroid11)||
Planet3.hitTestObject(Asteroid12))
{
gotoAndStop(1, "Scene 4");
}
}
//TIMER SECTION
function resetTimer():void
{
// check if timer already initialize
if(myTimer != null)
{
// just reset
myTimer.stop();
myTimer.reset();
}
else
{
// initialize timer and set a 45 sec delay;
myTimer = new Timer(4500,1);
myTimer.addEventListener(TimerEvent.TIMER, handleTimerTick);
}
myTimer.start();
}
function handleTimerTick(event:TimerEvent):void
{
// stop and null timer;
myTimer.stop();
myTimer.removeEventListener(TimerEvent.TIMER, handleTimerTick);
myTimer = null;
// goto my 4th scene
gotoAndStop(1, "Scene 4");
}
// whenever a hit test is performed and a timer reset is needed just call
resetTimer();
function onEnterFrame(e:Event):void {
var startTime:int=getTimer();
var currentTime:int=getTimer();
trace(currentTime);
if (currentTime>45000){
gotoAndStop(1, "Scene 6");
}
}
これらは本当に重要なすべてのシーンです。4 ~ 6 はほとんどがアニメーションで、マウス クリックなどです。シーン 4 ~ 6 ではタイマーは何も参照されていません。何か案は?必要に応じて追加情報を編集します。