Sunday, September 21, 2008

AS3 Event flow

Argh: AS3 Event Dispatcher views an event NOT as a class + type property, but just as a type property. Therefore:

new CustomEvent("onRollOver") is detected (and subsequently incorrectly cast) as new MouseEvent(MouseEvent.ROLL_OVER)

Very surprising.

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