Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 800385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:17:03+00:00 2026-05-14T23:17:03+00:00

I am extremely frustrated. I’m following a tutorial and mimicing it on my own.

  • 0

I am extremely frustrated. I’m following a tutorial and mimicing it on my own. I have been able to sort out most of the errors so far but this one has me stumped. I have tried replacing all of the class files with the tutorial specimen ones but i still get the error.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
     at com.senocular.utils::KeyObject/construct()
     at com.senocular.utils::KeyObject()
     at com.asgamer.basics1::Ship()
     at com.asgamer.basics1::Engine()

Now, not really understanding the error properly I paste dumped the files online for you to look at.

Ship class: textbin.com/78z35

Engine class: textbin.com/32b24

KeyObject class: textbin.com/p2725

As the error still occured when using the specimen class files I really have no idea where to begin. I will gladly try out any suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:17:04+00:00Added an answer on May 14, 2026 at 11:17 pm

    Tip: If you allow debugging, the exception will tell you the exact line in the source code where the Error is being thrown. Assuming you’re using the Flash IDE, go to publish settings and in the Flash tab check “Permit debugging”. This will makes thing much easier for you.

    Anyway, you have an error message. If you read it carefully, you can narrow down where the problem is. I don’t know if you are a programmer or you have any interest in being one; if you’re not, this answer will hopefully solve this particular problem. Anyway, if you don’t mind the rambling, let me tell you that if you’re interested in becoming a better programmer, paying attention to errors and learning how to debug / troubleshoot problems is one of the most important abilities you need to develop (if not the most important one); so maybe this will give you a few hints you can use to solve other problems as well.

    The message says:

    Cannot access a property or method of
    a null object reference.

    This means, at some point, you did something like this:

    someobject.someMethod();
    

    or

    someobject.someProperty = "foo";
    

    And someobject happened to be null. You can’t call methods or access properties of null.

    Ok, so now you know, somewhere, a variable had null as its value. Notice that the fact that you define a variable of property doesn’t mean it actually holds an object.

    This just says that a variable called mySprite can hold an object of the type Sprite:

    var mySprite:Sprite;
    

    But until at some point you create a Sprite and assign it to mySprite, the value held by mySprite will be null. If you do:

    mySprite.x = 0;
    

    Before initializing mySprite (i.e. before assigning a Sprite to it), you will have this same Null Reference error.

    This error message also offers some helpul context, which you can use to your advantage (in them old days… errors in Flash were silent; when things didn’t work, you had to manually trace down the problem).

    Ok, let’s break this error message down:

     at com.senocular.utils::KeyObject/construct()
     at com.senocular.utils::KeyObject()
     at com.asgamer.basics1::Ship()
     at com.asgamer.basics1::Engine()
    

    What you have above is called a stack trace. It basically tells you where the code blew up, and also gives you some context: how did you get there.

    The first line tells where the error actually occurred. That is, the construct method in the KeyObject object. That method was called from the KeyObject constructor, which was in turn called from the Ship constructor, which was in turn called from the Engine constructor.

    Now, let’s analyze how you got there, following the stack trace, bottom-up:

    Code in Engine constructor:

    ourShip = new Ship(stage);
    

    This creates a new Ship object. It passes a reference to the stage to the Ship constructor method.

    Code in Ship constructor:

    this.stageRef = stageRef;
    key = new KeyObject(stageRef);
    

    It grabs the ref passed in the previous step. It stores it and creates a new KeyObject object. The KeyObject constructor is passed a reference to the stage (which is the same ref that was passed from Engine to Ship).

    Code in KeyObject constructor:

    KeyObject.stage = stage; 
    keysDown = new Object(); 
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
    

    Now we got to the point where the error message told you the problem was. So, somewhere, you are using a variable that holds null and trying to access one of its methods or properties.

    This KeyObject stores the reference to stage it was passed in a static variable and creates a new Object object. So far, no problems. KeyObject cannot be null (it’s a reference to a Class). The second line itself cannot have this null problem either. So, if this is all the code in that method, the problem has to be either in the third or the fourth line. Both access the stage reference you passed and try to call a method (addEventListener) on it. So if one fails, the other will fail as well. Then, the third line: that’s where the problem has to be.

    So, at that point stage is null. As said previously, you can’t call a method on null, and that’s what the error is telling you.

    Now, if you get back to the first method call, you can see this is the origin of the problem:

    ourShip = new Ship(stage);
    

    You can be pretty sure that, at this point, stage was null. Add that to the fact that Engine extends MovieClip (which is in turn a DisplayObject), and to the fact that any DisplayObject has a reference to the stage object only while it’s added to the display list. The conclusion: an instance of Engine was not attached to the display list when its constructor was ran.

    A way to fix this (there might be others) could be moving the code in the Engine constructor to a separate function that will be executed only if / when the Engine object has a valid reference to the stage object.

    public function Engine() : void {
        if(stage) {
            initialize();
        } else {
            addEventListener(Event.ADDED_TO_STAGE,initialize);
        }
    } 
    
    private function initialize(e:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE,initialize);
        //  here goes the code that's currently in Engine constructor
    }
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone I'm currently extremely frustrated and can not figure this out have looked
I'm extremely new to Java, and have mostly just been teaching myself as I
I have an extremely hard time figurering out how classes needs to communicate with
I am extremely frustrated with ruby on Mac OS X. I have tried RVM
I am extremely new to SVN. I have created my own repository which is
I have an extremely large database and most of the space is the index
So I've been working on this for hours and I'm extremely frustrated. I don't
I have been extremely naughty. I have been developing a piece of software (I'm
I have the following extremely basic $.ajax function: function doAjax(url, args){ var retVal =
Right now, I'm extremely frustrated because I was in the process of developing some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.