# Error #1009: Cannot access a property or method of a null object reference

**URL:** https://forum.kirupa.com/t/error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/322269
**Category:** Uncategorized
**Created:** [May 16, 2011, 5:01pm UTC](https://forum.kirupa.com/t/error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/322269 "2011-05-16T17:01:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![12abhi12](https://avatars.discourse-cdn.com/v4/letter/1/9f8e36/32.png) [@12abhi12](https://forum.kirupa.com/u/12abhi12)
#### Post date: [May 16, 2011, 5:01pm UTC](https://forum.kirupa.com/t/error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/322269/1 "2011-05-16T17:01:44Z")

</div>

With this code I get the error “Error #1009: Cannot access a property or method of a null object reference.” because of the trace. But the same trace inside the if statement doesn’t cause a problem. Any reasons. I can’t refer to the object outside the if statement.

Note: This code is inside an EnterFrame event.

```auto

//bolt fire---------------
if (bolt_fire) {
	var bolt_no:Sprite = new heroweapon();
	bolt_no.name="xyz";//k
	addChild(bolt_no);

	bolt_no.x=hero_weapon.x;
	bolt_no.y=hero_weapon.y;
	bolt_no.rotation=angle2;
	angle3=angle2;
	trace(bolt_no.x,bolt_no.y,bolt_no.name);

	bolt_fire=false;
}
trace(bolt_no.x,bolt_no.y,bolt_no.name);

```
