6 Replies - 3293 Views - Last Post: 24 January 2012 - 01:48 PM

#1 mikex6989  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 101
  • Joined: 18-February 11

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

Posted 22 January 2012 - 01:08 PM

So I'm making a mario-esque type game. And my player hits bananas rather than coins, and so if i fall off the map - hitTestDie - then the player obviously dies. My problem is - If i don't collect all the bananas and fall off and die, then i get the error "Cannot access a property or method of a null object reference." When I debug it says that the line "player = MovieClip(root).player;" is the problem. Any ideas? This is code for the banana class. The code for the hitTestDie is in my main code...which I dont think is the issue.



package  {
	
	import flash.display.MovieClip;
	import flash.events.*;
	
	public class Banana extends MovieClip 
	
	{
		
		var player:MovieClip;
		var MainTimeLine = MovieClip(root);

	public function Banana() 
		
		{
			//constructor code
			
			this.addEventListener(Event.ENTER_FRAME, update);
			
		}
		
		function update(event:Event):void 
		{			
		
			player = MovieClip(root).player;			

			if(this.hitTestObject(player))
			{
				this.removeEventListener(Event.ENTER_FRAME, update);
				parent.removeChild(this);

				MainTimeLine.scoreCount = MainTimeLine.scoreCount + 50;
				
		} // end if
		


		
	}// end function update

	
}

}



This post has been edited by mikex6989: 22 January 2012 - 01:10 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Cannot access a property or method of a null object reference Problem

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Cannot access a property or method of a null object reference Problem

Posted 22 January 2012 - 01:56 PM

I'm not AS3 expert, but shouldn't

function update(event:Event):void



be

public function update(event:Event):void



because it might be default 'private' if not specified?
Was This Post Helpful? 0
  • +
  • -

#3 mikex6989  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 101
  • Joined: 18-February 11

Re: Cannot access a property or method of a null object reference Problem

Posted 22 January 2012 - 02:11 PM

that doesnt seem to be the issue..
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Cannot access a property or method of a null object reference Problem

Posted 22 January 2012 - 07:15 PM

Have you thought about redesigning your code? You most likely need to do that.
Was This Post Helpful? 0
  • +
  • -

#5 mikex6989  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 101
  • Joined: 18-February 11

Re: Cannot access a property or method of a null object reference Problem

Posted 22 January 2012 - 08:30 PM

i have several times. any help would be greatly appreciated..
Was This Post Helpful? 0
  • +
  • -

#6 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 994
  • View blog
  • Posts: 4,158
  • Joined: 14-February 08

Re: Cannot access a property or method of a null object reference Problem

Posted 23 January 2012 - 03:22 AM

Please post all of your code.
Was This Post Helpful? 0
  • +
  • -

#7 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Cannot access a property or method of a null object reference Problem

Posted 24 January 2012 - 01:48 PM

This is clearly a language comprehension issue regarding AS3 rather than a specific game programming issue.

Moving.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1