Skip to content
Sep 10 / Sidney de Koning

FullScreen mode in AS2

UPDATE: Source files are added and code is now in-post. Here is also a follow up on this article for AS3 and AIR

A client asked if it was possible to go FullScreen in AS2 and i said: “No, only from AS3, FlashPlayer 9″.

However i recently found out that this is possible to do it in AS2 , so below is a little code that will do this.

You do have to keep a couple of things in mind and put this into practice. Below is a little list:

  • To enable full-screen mode, add the allowFullScreen parameter in the object and embed tags in the HTML page that contains the reference to the SWF file, with allowFullScreen set to “true“, as shown in the following example:<param name=”allowFullScreen” value=”true” />

    <embed xsrc=”example.swf” allowFullScreen=”true” … >
  • The fullScreen setting is not supported for “windowless” (transparent windowless or opaque windowless) playback. If you have wmode set to opaque or transparent in the HTML page hosting the SWF file, the user will not be able to switch Flash Player to full-screen mode.
  • Full-screen mode is initiated in response to a mouse click or key press by the user; the movie cannot change Stage.displayState without user input. While Flash Player is in full-screen mode, all keyboard input is disabled (except keyboard shortcuts that take the user out of full-screen mode). A Flash Player dialog box appears over the movie when users enter full-screen mode to inform the users they are in full-screen mode and that they can press the Escape key to end full-screen mode.

Attached is the code and you can check the example HTML here.

And the sourcefiles are for download here

Code used in this example:

var myButton:mx.controls.Button;

Stage.scaleMode = "noScale";
myButton_btn.label = "Toggle Fullscreen";
myButton_btn.setSize(150,22);
var buttonListener:Object = new Object();

buttonListener.click = function(evt:Object) {
    Stage.displayState = Stage.displayState == "normal" ? "fullScreen" : "normal";
}

myButton_btn.addEventListener("click", buttonListener);

Please consider to buying me a coffee.

41 Comments

Leave a comment
  1. Jasmin / Feb 12 2008

    Please upload the file again! I get a 404 when i try to download it. Great tutorial by the way. Thank YOU!!!

  2. Bentley / Mar 8 2008

    Hey do you know if this only works with as2 in flash player 9 or does it also work in flash player 8?

    Thanks,
    Bentley

  3. Sidney de Koning / Mar 8 2008

    Hi Bently,

    No this does not work in Flash Player 8 because the displayState propery is not part of the player. I have not found a way to do this in FP8, unfortunately.

    Cheers,
    Sidney

  4. ugo / Jun 30 2008

    That’s what I was looking for.
    Thanks a lot.
    There’s no file for the download, so I’ll try right now.

    Ciao.

    Ugo

  5. Aman / Jul 25 2008

    I have FP 8 on my system. Still i am able to go to full screen mode when i press Full Screen button in You tube.
    How is it possible, if displayState property is not supported in FP 8?
    Or is the Youtube player that matters?

  6. Steven / Sep 4 2008

    this is great. i have been putting off work on updating my site to learn AS 3 and full screen is one of the reasons i was doing so. i am also getting an error when i try to download the files. would you be able to upload them again. thanks!

  7. sasha / Sep 12 2008

    The source files please!!

  8. Sidney de Koning / Sep 12 2008

    Hi Sasha and others,

    Will post the source files after the weekend for you.

    Greets Sid

  9. James / Sep 22 2008

    This seems like a good idea but if you’re developing in Flash8 with AS2 then Stage[displayState] is not supported.
    I have Flash 8 professional and the flashplayer is version 9. It still doesn’t work.
    Thanks for trying.

  10. James / Sep 22 2008

    Please ignore me. I’ve just checked and it works fine. I’d cut and pasted the object code and the quotes are in a different encoding.
    Thanks so much!

  11. darien / Sep 29 2008

    i would like to the source file.would you mind to share it again? i’m getting 404 file not found error like others.

    thanks

  12. tetemik / Sep 30 2008

    Hi.

    I create website with fullscreen, but i put this code in boton: on (release) { Stage.displayState = “fullscreen”;}

    My question: how i can start the fullscreen wihtout on(release)

    I try only in first frame: Stage.displayState = “fullscreen”;
    but it still doesn`t work!

    thanks

  13. Rick / Oct 10 2008

    Sid,
    I hate to ask, but the file seems to be still missing.
    thanks,!

  14. Kevin / Oct 15 2008

    Sorry to bother you. But I am just curious if you have posted the source files yet.

    This is the exact code I was looking for. Perfect to learn from.

  15. CristHoz / Nov 12 2008

    Gracias….esta bueno lo que estaba buscando….

  16. Sidney de Koning / Nov 12 2008

    Hi Crist,

    Gracias. Bueno oír que esto es lo que usted buscaba :)

    Sid

  17. Sidney de Koning / Nov 17 2008

    Hi tetemik,

    Yes you can, but you do have to listen for that event. You can do this by listening for the onResize event, set the paramater for the handling function to equal null and you can then call the function like you nomally would. Like so:

    addEventListener(Event.RESIZE, handlerForResize, false, 0, true);

    function handlerforResize( e:Event = null)
    {
    // place specific resizing here.
    }

    handlerforResize();

    Or you can leave the =null off and dispatch the event like so:

    dispatchEvent(new Event(Event.RESIZE));

    Hope this answers your question,

    Sid

  18. Tom / Nov 26 2008

    If you’re developing in Flash8 with AS2 then Stage[displayState] is supported IF you go to the following link, and make the changes to your Flash 8 Files. I did, and it works PERFECT with AS2. Be sure and read ALL the Comments. Some corrections are make there also. The ‘allowfullscreen’ tag is Required in the HTML file. It will NOT go full screen with just the flash file(.swf)

    http://julian.empiregn.com/2007/2/22/How-to-create-true-fullscreen-movies-with-Flash

  19. Ersin Ayhan / Dec 2 2008

    Thanks a lot from İstanbul, great tip.

  20. J / Dec 16 2008

    Thank You!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You Rock! :)

  21. Ersin Ayhan / Dec 26 2008

    I have a similar question..
    is there anyway or any component for fullscreen flvplayback component in as2 ?
    thanks.

  22. Nir / Jan 1 2009

    Thanks a lot exactly what i was looking for…
    Thanks… Thanks…. Thanks….

  23. Sidney de Koning / Jan 7 2009

    Yes there is, the standard FLVPlayback component in CS3 will do just that.

  24. Ersin Ayhan / Jan 16 2009

    First of all thank you for your reply.
    Yes there is a standart flvplayback component in cs3 but isn’t it for as3? i am asking a full screen video player in as2.

  25. 2e / Feb 11 2009

    This is awesome. Thanks a million!

  26. ze ming / Apr 1 2009

    great job! it works great

    but only one problem. works only if i use that button, i tried to use a self created button and nothing happen, having the same instance name and linkage,

    is there something i did wrong?

  27. Camsoary / May 3 2009

    hmm… nice :)

  28. Andrew / Aug 28 2009

    Thanks a lot for posting this. After searching for two days for various ways to make this work, this helps a lot! Peace!

  29. Laki / Sep 13 2009

    I would like to create an other self created button too, but if you see the component inspector, you’ll see the lot of parametes &schema too.

    Any good advice?

  30. Sidney de Koning / Sep 14 2009

    Can you explain what you want to do?

    Cheers Sid

  31. Darryl / Sep 17 2009

    I didn’t realize that I had to use the component button either. I tried my own over and over again and then decided to use the flash component button and it worked. Can this feature work if we create our own button instead of using the component button?

    It would be nice that when it opened full screen that the toggle button could disappear and then when the user toggled back the button would reappear. Thank you for posting!

  32. Sidney de Koning / Sep 17 2009

    Hi Darryl,
    Yes you can use your own buttons too of course, that’s the beauty of code :)

    If you want it to disappear just set it to myButton.visible = false; when ever the ‘fullscreen’ clause is set to true

    Below is an example of using you own custom button class (it is pseudo code, so replace it with actual classpaths etc. )
    import path.to.my.MyButton;

    Stage.scaleMode = “noScale”;
    var myButton:MyButton = new MyButton();

    myButton.addEventListener(“click”, buttonListener);
    myButton.label = “Toggle Fullscreen”;
    myButton._width = 150;
    myButton._height = 22;

    function buttonListener( evt:Object ):Void {
    Stage.displayState = Stage.displayState == “normal” ? “fullScreen” : “normal”;
    }

  33. Sidney de Koning / Apr 20 2010

    I’m not quite sure if it is in CS3 , but there is in AS2.

  34. carmela / May 26 2010

    Gracias! Thanks!!!

  35. Nishin / Aug 20 2010

    Hi ,
    I have a question.I am using Flash CS5 with AS2.In the fullscreen mode my mouse control are getting disabled.I am not able to click,

    Please help.

    Thanks!!!

  36. davenycity / Sep 15 2010

    great blog thank you

  37. Devon Sait / Apr 3 2011

    OR You could use my method.

    In the first frame of your movie enter the script

    fscommand(“fullscreen”, “true”);

    I did this in Flash Pro 8 under AS2.. Much easier.

  38. 98006887 / Jun 3 2011

    In the HTML file I have to use this line (when Flash5 generates my HTML)

    attributes.allowFullScreen = “true”;

  39. creation-it / Aug 4 2011

    If you want to publish for flash 8 in as2 use following code example:

    import flash.display.Stage;
    import flash.display.StageDisplayState;

    //FULLSCREEN
    btn_fullscreen.onRelease=function(){
    Stage.displayState = Stage.displayState == “normal” ? “fullScreen” : “normal”;
    }

Trackbacks and Pingbacks

  1. [Flash CS3] Fullscreen mode con CS3 e AS2? - FlepStudio forum
  2. FullScreen mode in AS3 and AIR – Confessions of an Flash Addict

Leave a comment