Fullscreen

Actionscript 3 Fix for the Flash Fullscreen Problem

Tuesday, December 15th, 2009

I have come across an error while working with Flash Fullscreen. The problem occurs when you have certain publish settings. The publish setting are in the html tab -> Window Mode -> Transparent Windowless. So the SWF file is basically transparent like a PNG image. It has trouble knowing where the stage is on this setting. So I came up with  a work around or fix that takes care of this. To fix this you have to create a background movieclip that resizes to the stage size that is hidden as well, so its alpha is zero, so that Flash recoginzes that your mouse is still over the swf file, I know its weird but this works.

So add a movieclip to the stage that is the same size of the stage, but make the color’s alpha zero. Make sure the instance name is “bg” then in the actionscript add this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    //import library files
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
 
    //reset the background movieclip function
    resetBGsize();
 
    //set the stage scalemode and alignment to no scale and top left
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;
 
    // add an event listener to the stage for when it is resized
    stage.addEventListener(Event.RESIZE, onResizeStage);
 
    //onresizestage function for the event listener, calls resetBGsize
    function onResizeStage(e:Event):void {
       resetBGsize();
    }
 
    //resetbgsize function resizes the background movieclip and centers it
    function resetBGsize():void {
       bg.width = stage.stageWidth;
       bg.height = stage.stageHeight;
       bg.x = stage.stageWidth / 2 - bg.width / 2;
       bg.y = stage.stageHeight / 2 - bg.height / 2;
    }

Hope this helps someone out.

Cya