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

**URL:** <https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/332327>\
**Category:** Uncategorized\
**Created:** [April 24, 2014, 8:18am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/332327 "2014-04-24T08:18:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayasha29](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Ayasha29](https://forum.kirupa.com/u/Ayasha29)\
**Post date:** [April 24, 2014, 8:18am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/332327/1 "2014-04-24T08:18:47Z")

</div>

Hi guy:)

I need urgent help. I am making a platform game for college. I have to handle it next week. The code works fine until the player has lost all his health and is game over.

The problem is in the coin class: Coin.as

The code looks like this:

```php
package {
	import flash.display.MovieClip;
	import flash.events.*;
	public class Coin extends MovieClip {
		var health = 6;
		var player_mc: MovieClip;
		private var MainTimeLine = MovieClip(root);
		public function Coin() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		private function init(event: Event): void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			this.addEventListener(Event.ENTER_FRAME, update);
		}
		function update(event: Event): void {
			trace(root);
			trace("variable:" + player_mc);
			player_mc = MovieClip(root).player_mc;
			if (this.hitTestObject(player_mc)) {
				this.removeEventListener(Event.ENTER_FRAME, update);
				parent.removeChild(this);
				MainTimeLine.coinCount++;
			}
		}
	}
}

```

The error message comes at line: 26, which is:

player\_mc = MovieClip(root).player\_mc;

Please help. I am trying now since a week to solve that problem, but without success:diss:
