There are three ways to do this:
Either check whether you are on frame2 in an enterFrame event:
ActionScript Code:
this.addEventListener(Event.ENTER_FRAME, enterFrame);
function(event:Event):void {
if (this.currentFrame() == 2) {
//do whatever
}
}
I wouldn't recommend this
You could also check if the object exists before referencing it. For example:
ActionScript Code:
//...random code beforehand
if (object) { //check if object exists
//run code referencing object
} else {
trace('object does not exist yet');
}
//...random code after
finally you could have a seperate keyframe/layer for the code that runs on frame2 so that it stays only on frame2
Probably the second method is the least clunky.
Hope that helps