February 10th, 2014, 10:59 AM
-
[Error #1009:] SetIntervalTimer/onTimer() and flash.utils::Timer/_timerDispatch()
Hi guys, I really could use some help with my flash game. It's the last error in an otherwise bug-free game, but I can't seem to fix it.
So I have a game where the hero (luna) has to collect stuff and must avoid getting hit by stuff (in my case it's broccoli). When the hero gets hit by a broccoli, she goes into "ouchpause", a short moment where she can't move. There's also a function called "ouchstoppen" where the game decides when to stop the "ouchpause".
The game is timed and the error I get occurs when the hero is in the "ouchpase" the second the game ends. Otherwise, the game ends smoothly. This is my error:
PHP Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at sleepytime_Final_fla::MainTimeline/ouchStoppen()
at Function/(URL)/AS3/2006/builtin::apply()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
and this is (what I hope to be) the relevant AS3 (I marked a few passages bold where I assume the error to be):
Code:
for (j = 0; j<game.brokkolibedarf; j++) {
// Creating the first broccolis
brokkoli[j] = new Brokkoli();
brokkoli[j].x = Math.random()*stage.stageWidth;
brokkoli[j].y = Math.random()*stage.stageHeight*(-1);
brokkoli[j].addEventListener(Event.ENTER_FRAME, brokkoliVerhalten);
addChild(brokkoli[j]);
}
var ouchInterval: uint;
function brokkoliVerhalten (e: Event): void
{
e.target.y += game.brokkolispeed;
if (luna.hitTestPoint(e.target.x, e.target.y, true)) {
game.ouch = true;
luna.gotoAndPlay("ouch"); // Abspielen der Autsch-Animation von Luna bei Kollision mit Brokkoli
ouchInterval = setInterval(ouchStoppen, game.ouchpause);
game.punkte -= 3; // Punktabzug bei Kollision zwischen Luna und Brokkoli
}
if (luna.hitTestPoint(e.target.x, e.target.y, true) || e.target.y > game.bottomBorder) {
e.target.x = Math.random()*stage.stageWidth;
e.target.y = Math.random()*stage.stageHeight*(-1);
}
}
function ouchStoppen() {
game.ouch = false;
luna.gotoAndStop("stand");
clearInterval(ouchInterval);
}
game.endeZeit = getTimer()+game.gesamtzeit;
game.balkenLaenge = zeit.zeitbalken.width;
zeit.addEventListener(Event.ENTER_FRAME, zeitAnzeige);
function zeitAnzeige (e: Event): void
{
var jetzt = getTimer();
var restzeit = game.endeZeit-jetzt;
// passt den Zeitbalken an
var neueBreite = game.balkenLaenge*(restzeit/game.gesamtzeit);
zeit.zeitbalken.width = neueBreite;
// Time has run out
if (jetzt>=game.endeZeit) {
zeit.removeEventListener(Event.ENTER_FRAME, zeitAnzeige);
luna.removeEventListener(Event.ENTER_FRAME, bewegen);
punktebox.removeEventListener(Event.ENTER_FRAME, punkteZeigen);
for(var i : int = 0; i < game.eisbedarf; i++)
{
eis[i].removeEventListener(Event.ENTER_FRAME, eisVerhalten);
}
for (var j : int = 0; j < game.brokkolibedarf; j++)
{
brokkoli[j].removeEventListener(Event.ENTER_FRAME, brokkoliVerhalten);
}
for (i = 0; i < eis.length; i++)
{
removeChild(eis[i]);
}
for (j = 0; j < brokkoli.length; j++)
{
removeChild(brokkoli[j]);
}
gotoAndStop("spielEnde");
}
};
Can anybody help? I'm really clueless here.
Thanks in advance!