Forums

ForumsProgramming Forum

Another problem

Posted Dec 7, '13 at 1:53pm

weirdlike

weirdlike

524 posts

Knight

alrighty fail on my theory, try doing this

function countdown(Event:TimerEvent)
        {
             if(time == 0)
            {
                timeTimer.stop();
                timeTimer.removeEventListener(TimerEvent.TIMER,countdown);

                trace("dispatching event");
                dispatchEvent(new GameEvent(GameEvent.GAMEOVER));
            }
            else
            {
                time -= 1;
                CountdownClockDisplay.text = time.toString();
            }
        }

 

Posted Dec 7, '13 at 2:46pm

alex57834

alex57834

89 posts

It has stayed the same no errors or warning just not showing the trace statement dispatching event it shows 2 other trace statements in the avatar class and gameclass but not this one.

 

Posted Dec 7, '13 at 3:21pm

weirdlike

weirdlike

524 posts

Knight

I tested this exact code and it worked for me maybe if you put it in the CountdownDisplayMain function instead of a separate function

var time:Number = 60;
var timeTimer:Timer;
           
    timeTimer = new Timer(1000);
        timeTimer.addEventListener(TimerEvent.TIMER,countdown);
        timeTimer.start();
           
    function countdown(Event:TimerEvent)
    {
         if(time == 0)
        {
            timeTimer.stop();
            timeTimer.removeEventListener(TimerEvent.TIMER,countdown);
   
            trace("dispatching event");
            //dispatchEvent(new GameEvent(GameEvent.GAMEOVER));
        }
        else
        {
            time -= 1;
            trace(time);
        }
    }

 

Posted Dec 8, '13 at 4:09pm

alex57834

alex57834

89 posts

I put it in the CountdownDisplayMain function and it plays the dispatching event trace statement but doesn't show the dark screen when it reaches 0. No errors either.

package  {
   
    import flash.display.MovieClip;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.events.*;
   
    public class CountdownDisplayMain extends MovieClip {
       
        var time:Number;
        var timeTimer:Timer;

        public function CountdownDisplayMain()
        {
            time = 60;
           
            CountdownClockDisplay.text = time.toString();
           
            timeTimer = new Timer(1000);
            timeTimer.addEventListener(TimerEvent.TIMER,countdown);
            timeTimer.start();
           
            function countdown(Event:TimerEvent)
            {
            time -= 1;
            CountdownClockDisplay.text = time.toString();
           
            if(time == 0)
            {
                timeTimer.stop();
                timeTimer.removeEventListener(TimerEvent.TIMER, countdown);
               
                trace("dispatchingEvent");
                dispatchEvent(new GameEvent(GameEvent.GAMEOVER));
            }
            else
            {
                time == 0;
                CountdownClockDisplay.text = time.toString();
            }
           
        }

    }
   
}

package  {
   
    import flash.display.MovieClip;
    import flash.events.*;
   
    public class Document extends MovieClip{
       
        public var game:GameClass;
        var darkGameScreen:DarkBackScreen;

        public function Document()
        {
            game = new GameClass(stage);
            game.addEventListener(GameEvent.GAMEOVER, onGameFinish);
            addChild(game);
        }
       
        public function onGameFinish(GameEvent)
        {
            trace("OnFinishFunction working");
           
            darkGameScreen = new DarkBackScreen();
            darkGameScreen.x = 0;
            darkGameScreen.y = 0;
            addChild(darkGameScreen);
           
            game = null;
        }

    }
   
}

package  {
   
    import flash.events.*;
   
    public class GameEvent extends Event {
       
        public static const GAMEOVER:String = "gameover";

        public function GameEvent(type:String)
        {
            super(type);
        }

    }
   
}

 

Posted Dec 8, '13 at 7:21pm

weirdlike

weirdlike

524 posts

Knight

if you are getting the trace then to my understanding it should be working, you could try the other method by commenting out this line and adding in your document class

game = new GameClass(stage);

//game.addEventListener(GameEvent.GAMEOVER, onGameFinish);
game.addEventListener("ENDGAME", dispatchTest);

addChild(game);

add this function like you did the onGameFinish

public function dispatchTest(event):void
{
      trace("it works")
}

and your CountdownDisplayMain class

if(time > 0)
{
       time -= 1;
       CountdownClockDisplay.text = time.toString();
}
else
{
       timeTimer.stop();
       timeTimer.removeEventListener(TimerEvent.TIMER, countdown);
               
       trace("dispatchingEvent");
       //dispatchEvent(new GameEvent(GameEvent.GAMEOVER));
       dispatchEvent(new Event("ENDGAME", true));

}

 

Posted Dec 9, '13 at 11:04am

alex57834

alex57834

89 posts

This is so aggravating to the point i wanna give up and start again :(

dispatchEvent( new Event("ENDGAME", true));

C:\\Users\\Alex The Best\\Documents\\My Games\\Platformer\\Classes\\CountdownDisplayMain.as, Line 35    1180: Call to a possibly undefined method Event.

and then I changed new Event ("ENDGAME")
to new GameEvent("ENDGAME")

and then it said incorrect number of arguments

 

Posted Dec 9, '13 at 11:50am

weirdlike

weirdlike

524 posts

Knight

Flash thinks that you are using the passing argument as an Event. In your CountdownDisplayMain class

change this

function countdown(Event:TimerEvent)

to this

function countdown(event):void

:D

 

Posted Dec 12, '13 at 4:02pm

alex57834

alex57834

89 posts

You know like I have done game = null
what is that supposed to do because i got it from a tutorial and it said it should remove game from sight I think and I just wanted want you would do instead.
Anyway game = null in my code doesn't do anything.

 

Posted Dec 12, '13 at 4:30pm

weirdlike

weirdlike

524 posts

Knight

public function Document():void
        {
            game = new GameClass(stage);
            game.addEventListener("GAMEOVER", onGameFinish);
            addChild(game);
        }
       
        public function onGameFinish(event):void
        {
            game.removeEventListener("GAMEOVER", onGameFinish);
            removeChild(game);
        game = null;

            darkGameScreen = new DarkBackScreen();
            darkGameScreen.x = 0;
            darkGameScreen.y = 0;
            addChild(darkGameScreen);
        }

 
Reply to Another problem

You must be logged in to post a reply!