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:
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!