Skip to main content
cjyoon1227
Known Participant
April 18, 2017
Answered

Error 1009

  • April 18, 2017
  • 1 reply
  • 2234 views

Hello! I'm debugging my work, and later on, the "Error 1009" appears. I really don't know how to solve that error and tbh, I don't really understand the error that I've always encountered. So here's my code:

import flash.text.*;

import flash.display.MovieClip;

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.MouseEvent;

import flash.events.Event;

import flash.display.DisplayObject;

import flash.geom.Point;

import flash.display.Stage;

import flash.display.Sprite;

import flash.utils.Timer;

import flash.events.TimerEvent;

nohint.visible = false;

txtSkor.text = String(iskoru);

txtLives.text = String(buhay);

txtHints.text = String(hinto);

txtHint.visible = false;

var gamestage: int = 0;

var gameTimer:Timer = new Timer(1000);

gameTimer.addEventListener(TimerEvent.TIMER, countDown);

gameTimer.start();

function countDown(event: TimerEvent): void {

  txtSec.text = String(sec);

  sec--;

  if (sec < 0) {

  gameTimer.stop();

  gameTimer.removeEventListener(TimerEvent.TIMER, countDown);

  maliWin.visible = true;

  quizquest.visible = false;

  ans11.visible = false;

  ans12.visible = false;

  ans13.visible = false;

  btnHint.visible = false;

  tim.visible = false;

  }

  ans11.addEventListener(MouseEvent.CLICK, buttones1);

  ans12.addEventListener(MouseEvent.CLICK, buttones2);

  ans13.addEventListener(MouseEvent.CLICK, buttones3);

  function buttones1(event: MouseEvent): void {

  corekWin.visible = true;

  iskoru += 10;

  //txtSkor.text = String(iskoru);

  trace("click successful");

  }

  function buttones2(event: MouseEvent): void {

  maliWin.visible = true;

  buhay -= 1;

  //txtLives.text = String(buhay);

  trace("click successful");

  }

  function buttones3(event: MouseEvent): void {

  maliWin.visible = true;

  buhay -= 1;

  //txtLives.text = String(buhay);

  trace("click successful");

  }

  maliWin.btnGobak.addEventListener(MouseEvent.CLICK, bey);

  function bey(event: MouseEvent): void {

  maliWin.visible = false;

  }

  corekWin.btnGo.addEventListener(MouseEvent.CLICK, gura);

  function gura(event: MouseEvent): void {

  corekWin.visible = false;

  quizquest.visible = false;

  ans11.visible = false;

  ans12.visible = false;

  ans13.visible = false;

  btnHint.visible = false;

  txtSec.visible = false;

  tim.visible = false;

  playergril.visible = true;

  stage.addEventListener(Event.ENTER_FRAME, loofa);

  }

}

function loofa(event: Event): void {

  if (doorOpen == false) {

  if (playergril.hitTestObject(pinto)) {

  pinto.gotoAndStop(2);

  playergril.visible = false;

  doorOpen = true;

  trace("door open");

  gotoAndStop(77);

  }

  }

}

btnHint.addEventListener(MouseEvent.CLICK, wee);

function wee(event: MouseEvent): void {

  hinto -= 1;

  txtHint.visible = true;

  if (hinto == 0) {

  nohint.visible = true;

  }

}

Note: the bolded line is the main cause of it or pointed error.

And the error says:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

  at RECOVER_dmgamedemover_fla::MainTimeline/countDown()[RECOVER_dmgamedemover_fla.MainTimeline::frame76:27]

  at flash.utils::Timer/_timerDispatch()

  at flash.utils::Timer/tick()

When I look at the side (Debug Console) contains some variables and objects. The other dynamic texts have been declared (flash.text.TextField) while the txtSec, the another dynamic text, is null. I have no idea on what's going on it. What would be the best solution for it? Any suggestions or ideas are appreciated. Thanks!

This topic has been closed for replies.
Correct answer kglad

Ok. But the txtSec is not removed from the stage. Related to my previous question: Walk a character using mouse event AS3, in frame 75, I've done walk my character then she got a key and then the button appears, and then when I click the button, the questionnaire appears (in the next frame) including that timer. My questionnaire here including answer boxes, hints, timer altogether in one keyframe.


the code you posted shows a lot of things (including named functions) nested inside countDown.

unnest all that.

function countDown(event: TimerEvent): void {

  txtSec.text = String(sec);

  sec--;

  if (sec < 0) {

  gameTimer.stop();

  gameTimer.removeEventListener(TimerEvent.TIMER, countDown);

  maliWin.visible = true;

  quizquest.visible = false;

  ans11.visible = false;

  ans12.visible = false;

  ans13.visible = false;

  btnHint.visible = false;

  tim.visible = false;

  }

}

  ans11.addEventListener(MouseEvent.CLICK, buttones1);

  ans12.addEventListener(MouseEvent.CLICK, buttones2);

  ans13.addEventListener(MouseEvent.CLICK, buttones3);

  function buttones1(event: MouseEvent): void {

  corekWin.visible = true;

  iskoru += 10;

  //txtSkor.text = String(iskoru);

  trace("click successful");

  }

  function buttones2(event: MouseEvent): void {

  maliWin.visible = true;

  buhay -= 1;

  //txtLives.text = String(buhay);

  trace("click successful");

  }

  function buttones3(event: MouseEvent): void {

  maliWin.visible = true;

  buhay -= 1;

  //txtLives.text = String(buhay);

  trace("click successful");

  }

  maliWin.btnGobak.addEventListener(MouseEvent.CLICK, bey);

  function bey(event: MouseEvent): void {

  maliWin.visible = false;

  }

  corekWin.btnGo.addEventListener(MouseEvent.CLICK, gura);

  function gura(event: MouseEvent): void {

  corekWin.visible = false;

  quizquest.visible = false;

  ans11.visible = false;

  ans12.visible = false;

  ans13.visible = false;

  btnHint.visible = false;

  txtSec.visible = false;

  tim.visible = false;

  playergril.visible = true;

  stage.addEventListener(Event.ENTER_FRAME, loofa);

  }

1 reply

kglad
Community Expert
Community Expert
April 18, 2017
cjyoon1227
Known Participant
April 18, 2017

This code is in frame 76, but the sec has been defined in frame 75. Same as iskoru, buhay, and hinto.

And the code for defining sec is:

var sec: int = 15;

kglad
Community Expert
Community Expert
April 18, 2017

then if the problematic line of code is bolded, txtSec is not defined when that line executes and the error appears.