ForumsProgramming ForumAnother problem

28 24920
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

classes cant look at themselves

take this

CountdownDisplayMain.CountdownClockDisplay.text = time.toString();

and change to this

CountdownClockDisplay.text = time.toString();

alex57834
offline
alex57834
88 posts
Nomad

It just stays blanks and i changed

time + 60;
to time = 60;

weirdlike
offline
weirdlike
1,299 posts
Prince

in the properties panel where you put the instance name look down to behavior and select single line and also take note of the width of your txt box, can it support 2 digits?

alex57834
offline
alex57834
88 posts
Nomad

Yes it is capable of storing 2 digits the text size is small enough to fit them in.

[URL=http://s927.photobucket.com/user/alex578344/media/cs6_zpsc42b4da4.png.html][IMG]http://i927.photobucket.com/albums/ad112/alex578344/cs6_zpsc42b4da4.png[/IMG][/URL]

weirdlike
offline
weirdlike
1,299 posts
Prince

the text and the box are both black change text to white

alex57834
offline
alex57834
88 posts
Nomad

How could i be so stupid

weirdlike
offline
weirdlike
1,299 posts
Prince

fine tuning... I do it all the time

alex57834
offline
alex57834
88 posts
Nomad

I have a Document class which now gives the error

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at avatar()
at GameClass()
at Document()



package {

import flash.display.MovieClip;

public class Document extends MovieClip{

public var game:GameClass;

public function Document()
{
game = new GameClass();
addChild(game);
}

}

}

weirdlike
offline
weirdlike
1,299 posts
Prince

some of your classes extend the stage

game = new GameClass(stage);

then in you game class

public function GameClass(stage):void

alex57834
offline
alex57834
88 posts
Nomad

Trying to use dispatch events now

C:\\Users\\Alex The Best\\Documents\\My Games\\Platformer\\Classes\\CountdownDisplayMain.as, Line 32 1137: Incorrect number of arguments. Expected no more than 0.

line 32 is the dispatch event line



Document class

package {

import flash.display.MovieClip;

public class Document extends MovieClip{

public var game:GameClass;

public function Document()
{
game = new GameClass(stage);
game.addEventListener(GameEvent.FINISH, onGameFinish);
addChild(game);
}

public function onGameFinish(gameEvent:GameEvent)
{
var darkBackScreenarkBackScreen = new DarkGameScreen();
darkBackScreen.x = 0;
darkBackScreen.y = 0;
addChild(darkBackScreen);

game = null;
}

}

}



function countdown(Event:TimerEvent)
{
time -= 1;
CountdownClockDisplay.text = time.toString();

if(time == 0)
{
timeTimer.stop();
dispatchEvent(new GameEvent(GameEvent.FINISH));
}
}

}

}

weirdlike
offline
weirdlike
1,299 posts
Prince

it kind of looks like you're reference a dispatching class, although I personally don't like using a class for dispatched event's it would probably look something like this

package
{
import flash.events.*;
public class GameEvent extends Event
{
public static const STARTGAME:String = "start";
public static const RESTARTGAME:String = "restart";
public static const FINISH:String = "finish";

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

----------------------------------------------------------------
this is how I like to do it

in your document class the listener would look like this

game.addEventListener("dispatch", onGameFinish);

then the dispatcher in your game class will look like this

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

the text that is quoted can be changed to whatever ex. "GAMEOVER" but the listener and the dispatch must match

weirdlike
offline
weirdlike
1,299 posts
Prince

Oh yeah and if you use a dispatching class change this line

public function onGameFinish(gameEvent:GameEvent)

to this

public function onGameFinish(GameEvent):void

if you use my method then it would look like this

public function onGameFinish(event):void

alex57834
offline
alex57834
88 posts
Nomad

Got another error now

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

alex57834
offline
alex57834
88 posts
Nomad

package {

import flash.events.*;

public class GameEvent extends Event {

public static const GAMEOVER:String = "gameover";

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

}

}






function countdown(Event:TimerEvent)
{
time -= 1;
CountdownClockDisplay.text = time.toString();

if(time == 0)
{
timeTimer.stop();
dispatchEvent(new Event("GAMEOVER", true)); = line33
}
}

}

}

weirdlike
offline
weirdlike
1,299 posts
Prince

I cant see the whole class, did you import events?

import flash.events.*;

Showing 1-15 of 28