# AS3 noob question

**URL:** https://forum.kirupa.com/t/as3-noob-question/270706
**Category:** flash
**Created:** [September 12, 2008, 3:57pm UTC](https://forum.kirupa.com/t/as3-noob-question/270706 "2008-09-12T15:57:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Burvs](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@Burvs](https://forum.kirupa.com/u/Burvs)
#### Post date: [September 12, 2008, 3:57pm UTC](https://forum.kirupa.com/t/as3-noob-question/270706/1 "2008-09-12T15:57:31Z")

</div>

Hi All,

So I’m trying out this AS3 lark for the first time at the moment and one thing is bothering me more than anything else:

Let’s say I have a FLA whose Document Class is Balls.as

On frame 1 of my FLA there is nothing on the stage.  
Later along the main timeline there is a frame labelled “ball”, on which is a movieclip with the instance name “myBall\_mc”.

Balls.as looks like this:

```auto

package {
	import flash.display.*;
	public class Balls extends MovieClip {
		public function Balls(){
			gotoAndStop("ball");
			myBall_mc.x=10;
		}
	}
}

```

But the above code returns the error:“TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at Balls()”

So it seems to me that you can’t move the playhead to a frame where a movieclip exists on the stage, and then immediately attempt to reference that movieclip.

Is that really the way things are in AS3? Similar code in AS2 works without a problem. Sounds like a right royal pain in the bum to me if that’s the case.

Obviously if you set a timer or something for a few milliseconds before trying to reference myBall\_mc it works fine. I expect the “proper” thing to do would be for me to make a separate “Ball” class of which myBall\_mc is an instance, and get it to reposition itself when it instantiates, but there are endless cases where the above code would be far more convenient.

Am I missing something here?

Thanks!
