user1964461
user1964461

Reputation:

ADDED_TO_STAGE event doesn't seem to work as I thought

I need to display a message for the user before a CPU hungry function starts. I start that function after the ADDED_TO_STAGE event is fired but half of the time, message box doesn't have enough time to be displayed when that heavy function starts. Is there any other way to make sure a message box is displaying before a heavy function starts processing things?

Upvotes: 0

Views: 118

Answers (1)

fsbmain
fsbmain

Reputation: 5267

Start heavy function in the next frame after popup window, use Event.ENTER_FRAME event for this. AVM executes as3 code in the beginning of frame and render graphics at the end, so your code that shows the window executed, but graphics is rendered only after heavy function, eg:

protected function init():void
{
    showPopup();
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private function onEnterFrame(event:Event):void
{
    removeEventListener(event.type, arguments.callee);
    startHeavyFunction()
}

Upvotes: 2

Related Questions