Tuesday, September 9, 2008

Elegantly call code after first frame(script) has executed?

private var __data:Object ={};
/**
* Constructor
*/
public function Content() {
this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
this.addEventListener(Event.ENTER_FRAME, afterFirstFrame);
}

public function addedToStage(e:Event)
{
}

public function afterFirstFrame(e:Event)
{
__data['frames'] = (__data['frames'] == undefined) ? 1 : __data['frames']++;
if (__data['frames'] > 1)
{
this.removeEventListener(Event.ENTER_FRAME, afterFirstFrame);
if (__isReadyToStart==undefined) trace('dispatch content ready:'+this);
delete(__data.framesPlayed);
}
}


I keep finding exceptions i need to hand, eg if frame calls stop() - and its starting to get stupid. So there is no way i can handle 'unknown' frame scripts. In as2 I could call setTimeout(afterFirstFrame, 1);

Need an EXIT_FRAME

No comments: