[AS3] TypeError #1009 Problem

Need help debugging this error

Page 1 of 1

3 Replies - 1265 Views - Last Post: 18 May 2009 - 01:27 PM

#1 icutenewb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-May 09

[AS3] TypeError #1009 Problem

Posted 17 May 2009 - 05:07 PM

OK, so, I'm making a game, in AS3, CS4, and I'm having the user move a circular character using the following code
stop();

var rightKeyDown:Boolean;
var leftKeyDown:Boolean;
var upKeyDown:Boolean;
var downKeyDown:Boolean
var keyPressed:int;
var speed = 0.5;
var cs = 0;
var friction = 0.96;

startMe();
function startMe():void {
	leftKeyDown = false;
	rightKeyDown = false;
	upKeyDown = false;
	downKeyDown = false;
	stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
	stage.addEventListener(KeyboardEvent.KEY_UP, releaseKey);
}

function pressKey(event:KeyboardEvent) {
	keyPressed = event.keyCode;
	if (keyPressed == Keyboard.LEFT) {
		leftKeyDown = true;
	}
	if (keyPressed == Keyboard.RIGHT) {
		rightKeyDown = true;
	}
	if (keyPressed == Keyboard.UP) {
		upKeyDown = true;
	}
	if (keyPressed == Keyboard.DOWN) {
		downKeyDown = true;
	}
	Jim.addEventListener(Event.ENTER_FRAME, driveJim);
}
function driveJim(event:Event):void {
	if (leftKeyDown) {
		cs -= speed;
	}
	if (rightKeyDown) {
		cs += speed;
	}
	if (upKeyDown) {
		cs += speed;
	}
	if (downKeyDown) {
		cs -= speed;
	}
	Jim.x += cs;
	Jim.y += cs;
	cs *= friction;
}
function releaseKey(event:KeyboardEvent):void {
	var key_:int = event.keyCode;
	if (key_ == Keyboard.LEFT) {
		leftKeyDown = false;
	}
	if (key_ == Keyboard.RIGHT) {
		rightKeyDown = false;
	}
	if (key_ == Keyboard.UP) {
		upKeyDown = false;
	}
	if (key_ == Keyboard.DOWN) {
		downKeyDown = false;
	}
}



...but whenever I press an arrow key, I get
"TypeError: Error #1009: Cannot access a property or method of a null object reference.
at JimTheCollectorPart1_fla::MainTimeline/pressKey()"

I don't know what this means really and the debugging isn't helping me at all! Any ideas on how to fix this?

Anything else you need I'll try to provide..

.. and if I really have to post the file I will =/

Is This A Good Question/Topic? 0
  • +

Replies To: [AS3] TypeError #1009 Problem

#2 SoLi  Icon User is offline

  • andydust.com

Reputation: 41
  • View blog
  • Posts: 1,438
  • Joined: 27-January 02

Re: [AS3] TypeError #1009 Problem

Posted 18 May 2009 - 07:56 AM

where is Jim defined? as a symbol on the stage or?
Was This Post Helpful? 0
  • +
  • -

#3 icutenewb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-May 09

Re: [AS3] TypeError #1009 Problem

Posted 18 May 2009 - 01:07 PM

View PostSoLi, on 18 May, 2009 - 06:56 AM, said:

where is Jim defined? as a symbol on the stage or?


Jim is a mc on stage, i havent learned packages and claases and whatever yet so for now yeah hes just a circle on the stage that im trying o move wih the keys
Was This Post Helpful? 0
  • +
  • -

#4 icutenewb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-May 09

Re: [AS3] TypeError #1009 Problem

Posted 18 May 2009 - 01:27 PM

View Posticutenewb, on 18 May, 2009 - 12:07 PM, said:

View PostSoLi, on 18 May, 2009 - 06:56 AM, said:

where is Jim defined? as a symbol on the stage or?


Jim is a mc on stage, i havent learned packages and claases and whatever yet so for now yeah hes just a circle on the stage that im trying o move wih the keys


Haha omg wow im so stupid.. I forgot to give jim an instance name =\
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1