Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Friday, August 15, 2008

Forcing your stage to resize

Friday, August 15, 2008   

Often times when we create a SWF or Projector that needs to run fullscreen, we set up our elements and try to count on the resize firing when we set the stage properties, but to ensure that the resize function actually fires, sometimes you need to force it. This isn't rocket science, but I think it's a decent tip.

You don't want to double up code or have a separate method in your resize event handler (the resize event handler requires an event type), so you can do it this way. I usually do this in a document class constructor, but you could do it anywhere you want.
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.addEventListener( Event.RESIZE, onResize );

// Here is where you can force the onResize

stage.dispatchEvent( new Event( Event.RESIZE ));

// Later on...
private function onResize( e:Event ):void
{
// code
}
 
 Return to the main page
Comments:

There are currently 1 Comments:

Anonymous drMikey said...
“thats a pretty clean solution to the problem.

i usually set my resize handler with (evt:Event=null) and then just call the method directly without passing anything.

a good tip!”
 
 Leave a comment