# Parent and classes

**URL:** <https://forum.kirupa.com/t/parent-and-classes/277151>\
**Category:** Uncategorized\
**Created:** [December 8, 2008, 5:50pm UTC](https://forum.kirupa.com/t/parent-and-classes/277151 "2008-12-08T17:50:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mafordha](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mafordha/32/668_2.png) [@mafordha](https://forum.kirupa.com/u/mafordha)\
**Post date:** [December 8, 2008, 5:50pm UTC](https://forum.kirupa.com/t/parent-and-classes/277151/1 "2008-12-08T17:50:20Z")

</div>

Hello,

I have searched for this problem, and found no solution. I am sure it is not an uncommon question, however.

I am having difficulty with ‘parent’ in Actionscript 3 accostiated with items that are added via addChild().

The following call to ‘tracer’ from the MC ‘Box’ works:

```auto

// Document Class

package {
	import flash.display.MovieClip;

	public class MyProject extends MovieClip
	{
		public function MyProject()
		{
		}
		
		public function tracer():void
		{
			trace("Testing...");
		}
	}
}

// Box Class - An instance of 'Box' was added manually to the stage in Flash

package
{
	import flash.display.MovieClip;
		
	public class Box extends MovieClip
	{
		public function Box()
		{
		       MovieClip(this.parent).tracer();
		}

	}
}

```

HOWEVER, when the ‘Box’ movie is NOT added to the stage manually, but added via addChild() from the document class, like this…

```auto

// Document Class
package {
	import flash.display.MovieClip;

	public class MyProject extends MovieClip
	{
		public function MyProject()
		{
			var b:Box = new Box();
			addChild(b);
		}
		
		public function tracer():void
		{
			trace("Testing...");
		}
	}
}

```

… it returns the error:

```auto

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Box()
	at MyProject()

```

Is it possible to call ‘tracer()’ from ‘Box’ when the ‘Box’ is added via addChild()?

Thank you for your help!
