Wednesday, August 12, 2009

Fullscreen Flash on OSX

If you're having trouble getting true fullscreen flash in OSX, I have a solution for you.

The following code:

stage.displayState='fullScreen';

*should* set your flash clip to flawless fullscreen mode, and does in most OSes. Using OSX Leopard and Flash CS3, however, your flash clip still has the title bar (with the close, minimize, and + buttons). Not exactly behavior as documented.

At first I found the suggestion here to put the above code into frame 2 - that seemed to work for some people. That didn't work for me, but if I put a 530 millisecond or greater delay in frame 1 before moving on to frame 2 it would work (529 or less would not):


stop();
function goNext(te:TimerEvent):void
{
t.stop();
t.removeEventListener(flash.events.TimerEvent.TIMER, goNext);
gotoAndStop(2);
}
var t:Timer = new Timer(530, 1);
t.addEventListener(flash.events.TimerEvent.TIMER, goNext);
t.start();
I then tried putting fullscreen code directly in goNext just to see what would happen:

stop();
function goNext(te:TimerEvent):void
{
t.stop();
t.removeEventListener(flash.events.TimerEvent.TIMER, goNext);
stage.displayState='fullScreen';
}
var t:Timer = new Timer(530, 1);
t.addEventListener(flash.events.TimerEvent.TIMER, goNext);
t.start();

That didn't work, which meant either Flash really liked having that code in frame 2, or it just took that little bit longer to transition to frame 2 than it did to just run stage.displayState='fullScreen' inline. So I switched the delay to a full second:

stop();
function goNext(te:TimerEvent):void
{
t.stop();
t.removeEventListener(flash.events.TimerEvent.TIMER, goNext);
stage.displayState='fullScreen';
}
var t:Timer = new Timer(1000, 1);
t.addEventListener(flash.events.TimerEvent.TIMER, goNext);
t.start();


... and it once again worked.

So it looks like the problem is we're waiting for either OSX or Flash to do something in the background before it's ready to go fullscreen. Until this bug is fixed you're going to have to take a good guess at about how long to delay before going fullscreen if you don't want to end up with a titlebar.

No comments: