ForumsProgramming ForumAnother problem

28 24630
alex57834
offline
alex57834
88 posts
Nomad

I get the error

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);

  • 28 Replies
weirdlike
offline
weirdlike
1,299 posts
Prince

note: if you are using an event class the dispatcher would look like this

dispatchEvent(new GameEvent(GameEvent.GAMEOVER));

alex57834
offline
alex57834
88 posts
Nomad

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));
}
}

}

}

weirdlike
offline
weirdlike
1,299 posts
Prince

okie I have a theory you could test and I'll explain it, but bear with me this is untested

game.addEventListener(GameEvent.GAMEOVER, onGameFinish);

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

dispatchEvent(new GameEvent(GameEvent.GAMEOVER, true));

alex57834
offline
alex57834
88 posts
Nomad

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.

weirdlike
offline
weirdlike
1,299 posts
Prince

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();
}
}

alex57834
offline
alex57834
88 posts
Nomad

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.

weirdlike
offline
weirdlike
1,299 posts
Prince

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);
}
}

alex57834
offline
alex57834
88 posts
Nomad

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);
}

}

}

weirdlike
offline
weirdlike
1,299 posts
Prince

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&quot
}


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));

}

alex57834
offline
alex57834
88 posts
Nomad

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&quot
to new GameEvent("ENDGAME&quot

and then it said incorrect number of arguments

weirdlike
offline
weirdlike
1,299 posts
Prince

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

alex57834
offline
alex57834
88 posts
Nomad

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.

weirdlike
offline
weirdlike
1,299 posts
Prince

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);
}

Showing 16-28 of 28