CountdownDisplayMain.as, Line 16 1119: Access of possibly undefined property CountdownClockDisplay through a reference with static type Class. and also the same on line 27
package { import flash.display.MovieClip; import flash.events.TimerEvent; import flash.utils.Timer; public class CountdownDisplayMain extends MovieClip { var time:Number; var timeTimer:Timer;
public function CountdownDisplayMain() { time + 60; CountdownDisplayMain.CountdownClockDisplay.text = time.toString(); timeTimer = new Timer(1000); timeTimer.addEventListener(TimerEvent.TIMER,countdown); timeTimer.start(); } function countdown(Event:TimerEvent) { time -= 1; CountdownDisplayMain.CountdownClockDisplay.text = time.toString(); }
} }
In my document class i have the following
var countdownDisplayMain:CountdownDisplayMain = new CountdownDisplayMain(); countdownDisplayMain.x = 50; countdownDisplayMain.y = 350; addChild(countdownDisplayMain);
Got no errors but it isn't showing the darkGameScreen screen when the time has reached 0.
package { import flash.events.*; public class GameEvent extends Event { public static const GAMEOVER:String = "gameover";
public function GameEvent(type:String) { super(type); }
} }
package { import flash.display.MovieClip; import flash.events.*; public class Document extends MovieClip{ public var game:GameClass; var darkGameScreenarkBackScreen;
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.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(); dispatchEvent(new GameEvent(GameEvent.GAMEOVER)); } }
it is not the game class that is dispatching the event, but how can you add a listener to a class that wasn't declared as a variable... well you cant, so what you need to do is bubble the dispatching event from child to parent in this case the parent is the GameClass and the child is CountdownDisplayMain
error: C:\\Users\\Alex The Best\\Documents\\My Games\\Platformer\\Classes\\CountdownDisplayMain.as, Line 33 1137: Incorrect number of arguments. Expected no more than 1.
I think the dispatch events are working just i put a trace statement into the if (time == 0); thingy and it didn't show the trace statement but the timeTimer does stop at 0 so that should be working. Its just the darkGameScreen which isn't showing.
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.
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 darkGameScreenarkBackScreen;
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); }
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
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.
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;