# Senocular's key.isDown Help!

**URL:** <https://forum.kirupa.com/t/senoculars-key-isdown-help/252869>\
**Category:** Uncategorized\
**Created:** [February 24, 2008, 8:25pm UTC](https://forum.kirupa.com/t/senoculars-key-isdown-help/252869 "2008-02-24T20:25:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andymac1990](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@andymac1990](https://forum.kirupa.com/u/andymac1990)\
**Post date:** [February 24, 2008, 8:25pm UTC](https://forum.kirupa.com/t/senoculars-key-isdown-help/252869/1 "2008-02-24T20:25:44Z")

</div>

Hi I have done a lot of actionscript 2.0 and am very new to actionscript 3.0. So here is the deal. I understand that there is a slight frustration about the taking away of the key.isDown(Key.UP) this from AS2.0 and I am currently making a fighting game with a lot of keys being pressed. I have come across senocular’s key.isDown(Keyboard.UP) which is amazing (Thanks!) but I have run into a small problem. Here is my situation:

I have a fighter movie clip in my library which has linkage to actionscript. I made a class for this fighter and in the class has all the controls for the fighter so that I could just I can easly make a fighter in the timeline and have all it’s Keyboard controls set up.

for example the mcFighter is a movie clip which has a linkage class of ninja\_mc in the main timeline I have code that is somewhat like this:

```auto

var ninja_mc:mcNinja = new mcNinja()

addChild(ninja_mc);
ninja_mc.x = 100;
ninja_mc.y = 100;

```

And Here is the mcNinja.as file that is liked to the movie clip in my library:

```auto

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.ui.Keyboard;
    import KeyObject;

    public class mcNinja extends MovieClip
    {
        private var key:KeyObject = new KeyObject(stage);
        public var keyLeft:Boolean;
        public var keyRight:Boolean;
        
        public function mcSasuke()
        {
            this.addEventListener(Event.ENTER_FRAME, keysDown);
        }
        
        private function keysDown(event:Event):void
        {
            if (key.isDown(Keyboard.LEFT))
            {
                keyLeft = true;
            }
            if (key.isDown(Keyboard.RIGHT))
            {
                keyRight = true;
            }
        }
    }
}

```

Now when I compile the game I get this ERROR:

[FONT=Courier New]TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at KeyObject/construct()  
at KeyObject()  
at mcNinja()  
at Main\_fla::MainTimeline/initializeGame()  
at Main\_fla::MainTimeline/frame1()

[FONT=Verdana]I believe that there is something wrong with passing “stage” in here but this method, made by senocular, needs stage passed in:

[/FONT][/FONT]

```auto
private var key:KeyObject = new KeyObject(stage);

```

There is probaly a simple fix to this but again, I’m new to AS3 or AS for that matter so any help. would be greatly appreciated. Thanks. 🙂
