Wednesday, July 14, 2010

Fullscreen toggling using Actionscript 3

Sometimes it is needed to create an option to view flash in fullscreen. In AS3, this can be done with just one line of code:

stage.displayState = StageDisplayState.FULL_SCREEN;

Toggle button is probably the best option to allow the user change the viewing mode. This function can be used on a button or any other event listener:
function ToggleFullscreen():void
    if (stage.displayState == StageDisplayState.NORMAL) {
        stage.displayState = StageDisplayState.FULL_SCREEN;
    } else {
        stage.displayState = StageDisplayState.NORMAL;

Note, that this code will only work, if the HTML object code allows fullscreen:
<param name=”allowFullScreen” value=”true”>

No comments:

Post a Comment