• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Error 1009

New Here ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

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!

Views

852

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 19, 2017 Apr 19, 2017

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

...

Votes

Translate

Translate
Community Expert ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

The timer (related to the problematic line) actually works but when I proceed to the next frame, the error 1009 suddenly appears and the bolded line is the cause. I don't really understand why? And I can't find any solution here.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

when you change frames is txtSec removed from the stage and your timer loop continues to executed?

if so, either terminate that loop, or if you want to continue the textfield display, make sure txtSec is not removed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

Here's a screenshot of my work:

I put the txtSec (pointed in arrow) in frame 76 where the code is there (in orange highlight and that code that I've mentioned here).

And here it is:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

again, when you change frames (and see the error) is txtSec removed from the stage and your timer loop continues to executed?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

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

  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

Hello! I already did what you said. But still, it throws an error 1009 and still, txtSec.text = String(sec); is the problematic line. I really dunno how can I solve it? Is it affected from a frame? Because I combined the questionnaire contents (timer, answer box, hint button, hint text) together in one frame.

But now, I placed the contents of a questionnaire into quizquest movieclip, I separate each of them into different layers. But still, it throws an error and quizquest.txtSec.text = String(sec); is the problematic line. What should I do? Any suggestions will be appreciated. Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

P.S. Here is the contents of a questionnaire inside quizquest and it is in the frame 76:

Inside the quizquest movieclip:

And the updated 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;

quizquest.nohint.visible = false;

quizquest.txtSec.text = String(sec);

txtSkor.text = String(iskoru);

txtLives.text = String(buhay);

txtHints.text = String(hinto);

var sec: int = 15;

quizquest.txtHint.visible = false;

var gameTimer: Timer = new Timer(1000);

gameTimer.addEventListener(TimerEvent.TIMER, countDown);

gameTimer.start();

function countDown(event: TimerEvent): void {

  quizquest.txtSec.text = sec; // it is already declared above

  sec--;

  if (sec < 0) {

  gameTimer.stop();

  gameTimer.removeEventListener(TimerEvent.TIMER, countDown);

  maliWin.visible = true;

  }

  quizquest.visible = false;

}

quizquest.ans11.addEventListener(MouseEvent.CLICK, buttones1);

quizquest.ans12.addEventListener(MouseEvent.CLICK, buttones2);

quizquest.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;

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

  }

  }

}

quizquest.btnHint.addEventListener(MouseEvent.CLICK, wee);

function wee(event: MouseEvent): void {

  hinto -= 1;

  quizquest.txtHint.visible = true;

  if (hinto == 0) {

  quizquest.nohint.visible = true;

  }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

Oops! Sorry for my mistake. Actually, it is:

quizquest.nohint.visible = false;

txtSkor.text = String(iskoru);

txtLives.text = String(buhay);

txtHints.text = String(hinto);

var sec: int = 15;

quizquest.txtSec.text = String(sec);

quizquest.txtHint.visible = false;

var gameTimer: Timer = new Timer(1000);

Not this code in my previous reply.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

if the error is on frame 76 of your main timeline and on frame 76 you have a movieclip (eg, with instance name mc) and inside that movieclip you have a textfield txtSec, you should be using

mc.txtSec.text = whatever;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2017 Apr 22, 2017

Copy link to clipboard

Copied

I'm already using that method, and still, same error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2017 Apr 22, 2017

Copy link to clipboard

Copied

someone will probably need to download and fix your file because of the way it's organized and because it's so difficult to understand your organization in a forum.

in the future, this excerpt from a book i wrote (Flash Game Development: In a Social, Mobile and 3D World) may help you:

There are some basic differences between timeline coding and coding in class files (class coding, for short). There is no requirement that you do all of one or all of the other. You can combine timeline and class coding in any Flash project.

But, in general, you should limit your timeline coding to not much more than a stop(), gotoAndPlay() or gotoAndStop(). Any more actionscript than one of those three methods attached to a timeline, I will refer to as significant timeline coding.

For elementary projects (eg, 100 or fewer lines of code), significant timeline coding, using one frame in one timeline to attach all your code, is acceptable. That is not necessarily good coding practice but it is acceptable in those circumstances.

For debugging and testing, you can add code anywhere you need for convenience. Debugging and testing code will not need editing, extending or maintaining and those are all drawbacks of significant timeline coding.

For anything more complex, like all but the simplest games, you should use class files for your coding. It may seem more difficult and time-consuming to set-up a project using class files but it much easier to debug, prevent bugs, maintain, and extend a game when using class files.

If you have ever added as little as one or two thousand lines of code to a timeline, you have probably encountered an actions panel delay. It takes some versions of Flash Pro a few seconds (or more) to display all the code that you are likely to create when coding a complex game, if that code is on a timeline. It takes even longer to scroll through all that code looking for a section you want to edit.

Spreading code across more than one frame of a timeline and especially in more than one timeline is a time-wasting mess and strongly discouraged. Anyone who has ever worked on a Flash file with significant bits of code spread over more than one timeline more than a few weeks after creating that code understands the incredible amount of time that can be wasted looking for pertinent code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2017 Apr 24, 2017

Copy link to clipboard

Copied

Thanks for your tip. Now I'm experiencing much difficulties in creating a code. I already made a class file but it is hard to understand the error. But now I'm in trouble. I don't really understand what would be the main cause of error. Actually my coding there is kinda messy yet it is working, but the error still appears.

I wanna ask if I'll pressed Ctrl+Shift+Enter then the AIR debugger performs, and suddenly, it stopped and there's pointed line that maybe the cause of error (e.g. frame 76, line 58), and I edited my code in that particular frame number, then repeat debugging, and then the pointed line is in the same frame and line number, but I assume that particular line number is actually a space or no code yet there's a code in the next line. What do you think would be the cause/s of it? Any tips or suggestions?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2017 Apr 25, 2017

Copy link to clipboard

Copied

the debugger almost never is wrong.

but it can point to a line number and the problem is in the line of code above or below the indicated line.  make sure you've ticked 'permit debugging'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 25, 2017 Apr 25, 2017

Copy link to clipboard

Copied

Yes, I did permit debugging. How about a movieclip object that already exists in a particular frame number but is actually a null object? I double checked both the instance name and in the code, their spellings are same and correct (e.g. quizquest2 (instance name) is the movieclip object, it actually exists in a frame (let say frame 76), and the code is in the frame 76, the spelling of the instance name and in the code is both similar, and I did duplication of an object (e.g. it came from quizquest), that object is 'QuizQuest copy' and the instance name is quizquest2, but inside of quizquest2 has answer boxes (assume that one of the answer boxes' instance name is ans21), timer (instance name: secBox), hint button (instance name: btnHint), and hint texts (instance names: hintBox for hint and nohint if it is out of hint)). When I trace the two quizquest movieclips, when I look at the output box, [object QuizQuest] appears for quizquest movieclip while for quizquest2, null appears that's why I can't proceed to the next frame and it may be the main cause of error since it points out to the line (let say line 18) where quizquest2 exists in that line. Can I declare a movieclip? What should I do to make a quizquest2 movieclip becomes not null?

P.S.: Oops! This discussion thread becomes longer

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2017 Apr 25, 2017

Copy link to clipboard

Copied

LATEST

there are a lot of ways to create problems when you use timeline coding (as opposed to class coding).  and it can be impossible to see how the problem was created without checking the history panel (assuming it's long enough).

there's only one way to ensure an object that first appears on a timeline in frame x can be referenced with code in frame y and that's to assign an instance name in that first keyframe that contains the object and then add keyframes (non-empty) in other frames where that object needs to be referenced.  anything else can be problematic.

so whatever's triggering that 1009 should be in its own layer (so it's easy to find) in a keyframe where it has an instance name assigned (in the property panel).  that's either frame 1 or all the frames preceding that keyframe are empty.  then extend that layer to the end of your timeline.

you should now be able to test your code references.  you can then add keyframes wherever you want on that layer but do NOT remove that object from any keyframe if you need to reference it later in the timeline.  re-adding the object after removing it is a common cause of failure.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines