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:
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:
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]
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.