# Cannot access stage properties from as file

**URL:** <https://forum.kirupa.com/t/cannot-access-stage-properties-from-as-file/287332>\
**Category:** flash\
**Created:** [April 29, 2009, 3:09pm UTC](https://forum.kirupa.com/t/cannot-access-stage-properties-from-as-file/287332 "2009-04-29T15:09:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spell2az](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Spell2az](https://forum.kirupa.com/u/Spell2az)\
**Post date:** [April 29, 2009, 3:09pm UTC](https://forum.kirupa.com/t/cannot-access-stage-properties-from-as-file/287332/1 "2009-04-29T15:09:57Z")

</div>

Hi i’ve been searching a lot of forums for a solution to this problem but i still cannot figure it out .

here is my code

```auto
package
{
	import flash.events.*
	import flash.display.*
	public class Control extends MovieClip
	

	{
		private var leftKey:Boolean = false
		private var rightKey:Boolean = false
		private var upKey:Boolean = false
		private var downKey:Boolean = false
		private const SPEED:int = 5
		
		
		
		private function keyPressed(event:KeyboardEvent):void
		{
			if(event.keyCode == 37)
			{
				leftKey = true;
				trace("number 37 pressed")
			}
			if(event.keyCode == 39)
			{
				rightKey = true;
			}
			if(event.keyCode == 38)
			{
				upKey = true;
			}
			if(event.keyCode == 40)
			{
				downKey = true;
			}
			
		}
		private function keyReleased(event:KeyboardEvent):void
		{
			if(event.keyCode == 37)
			{
				leftKey = false;
			}
			if(event.keyCode == 39)
			{
				rightKey = false;
			}
			if(event.keyCode == 38)
			{
				upKey = false;
			}
			if(event.keyCode == 40)
			{
				downKey = false;
			}
		
		}
		
		private function moveStudent():void
		{
			if(leftKey == true)
			{
				targetObject.stage.x -= SPEED
				trace("key down ")
			}
			if(rightKey == true)
			{
				targetObject.stage.x += SPEED
			}
			if(upKey == true)
			{
				targetObject.stage.y -= SPEED
			}
			if(downKey == true)
			{
				targetObject.stage.y += SPEED
			}
		}
		public var targetObject:DisplayObject
		
		private function go(event:Event):void
		{
			trace("go")
		}
		public function Control(object:DisplayObject)
		{
			targetObject = object
			stage.addEventListener(Event.ADDED_TO_STAGE, go)
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed)
			
			//object.addEventListener(KeyboardEvent.KEY_UP, keyReleased)
			//object.addEventListener(Event.ENTER_FRAME, moveStudent)

			
			//keyPressed();
			//keyReleased();
			moveStudent();
		}
		
		
	}
}

```

everything is fine except stage.addEventListener…etc  
because of these two lines im getting error

TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at Control()  
at DragGame()  
at dropstop\_fla::MainTimeline/frame1()  
i’ve tried to figure it out with my lecturer but he couldn’t hep me with this one,does it have to do anything with ADDED\_TO\_STAGE event?just a guess.really desperate for solving this issue, thanks for any help
