# Beginner problem with classes :(

**URL:** <https://forum.kirupa.com/t/beginner-problem-with-classes/316854>\
**Category:** flash\
**Created:** [December 4, 2010, 10:46am UTC](https://forum.kirupa.com/t/beginner-problem-with-classes/316854 "2010-12-04T10:46:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomii01](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@tomii01](https://forum.kirupa.com/u/tomii01)\
**Post date:** [December 4, 2010, 10:46am UTC](https://forum.kirupa.com/t/beginner-problem-with-classes/316854/1 "2010-12-04T10:46:50Z")

</div>

Hi!

I’m trying to learn how to use classes in AS3 and I’ve run into a problem…

- I have a main class and another class for the bullets the character shoots.
- The bullets are supposed to move towards the crosshair when added to stage.

The crosshair is added to the stage directly, but even so I get this error that says “Access of undefined property aimMC”.

Oh, and the bullets are added to stage when I press SPACE.

```auto

public function Main() {
			
			drawObjects();

```

```auto

private function drawObjects():void {
			player.x = stage.stageWidth /2;
			player.y = 380;
			stage.addChild(player);
			
			aimMC.x = stage.stageWidth /2;
			aimMC.y = stage.stageHeight /2;
			stage.addChild(aimMC);
		}

```

Then, in the bullet class, I have:

```auto

public function AmmoMC() {
			
			this.addEventListener(Event.ENTER_FRAME, moveAmmo, false, 0, true);

```

```auto

private function moveAmmo(evt:Event):void {
			
			var x:Number = aimMC.x;
			var y:Number = aimMC.y;
			this.x += (x - this.x);
			this.y += (y - this.y);
			
			if (_xpos < 0 || _xpos > stage.stageWidth || _ypos < 0 || _ypos > stage.stageHeight) {
				removeEventListener(Event.ENTER_FRAME, moveAmmo);
				parent.removeChild(this);
			}
		}

```

What do you think is wrong?
