Home > ActionScript 3, Basics, Flash CS3, Functions, full screen > Full Screen in ActionScript 3

Full Screen in ActionScript 3

I’ve gotten several hits from search engines with the keywords “Full Screen” and I don’t have anything on here that actually shows how to do full screen. It’s pretty easy. Here is the code:

import flash.display.StageDisplayState;

function goFullScreen():void
{
    if (stage.displayState == StageDisplayState.NORMAL) {
        stage.displayState=StageDisplayState.FULL_SCREEN;
    } else {
        stage.displayState=StageDisplayState.NORMAL;
    }
}

stage.addEventListener(MouseEvent.CLICK, _handleClick)

function _handleClick(event:MouseEvent):void
{
    goFullScreen();
}

This code is pretty simple. What it does is make the Flash movie go full screen when you click anywhere on the stage. This could easily be tweaked so that it responds to a button click.

Keep in mind that this will only work when you view this in the browser. It’s doesn’t work when compiled inside of Flash CS3.

One thing you want to make sure of is that your embed code has the
<param name=”allowFullScreen” value=”true” /> tag in the param tags list as well as the allowFullScreen as an attribute in the embed tag. Here is an example:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="Untitled-3" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<font color="#0000FF"><param name="allowFullScreen" value="true" /></font>
<param name="movie" value="Untitled-3.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="Untitled-3.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="Untitled-3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
  1. May 7, 2008 at 3:13 pm | #1

    Hey thanks for the code. Seems like AS3 will make life easy. I am very new to flash and don’t know much about AS. When I use your code every thing works fine but what i am looking for is enter button that opens page (actual whole site) in fullsceen.

    I understand this code only allows the SAME page to toggle but can we do it the other way? or the whole site on Fullscreen right from start (rather then button)

    Thanks in advance for help.

  2. May 7, 2008 at 10:49 pm | #2

    Yes, you can make the page go to full screen by calling the goFullScreen() function above outside of the _handleClick function. That should make your movie go full screen automatically without having to click anything.

  3. Sinan
    May 14, 2008 at 5:22 am | #3

    it doesn’t work that only you call the function itself without a button or something click. How can i make it auto full screen?

  4. George
    May 19, 2008 at 3:59 am | #4

    you need to add an enterframe thing. im new to flash so dont know the exact code but that should do it straight away when you start ur flash project

  5. May 19, 2008 at 8:17 am | #5

    George,

    You’re probably right. You should be able to do this:

    function goFullScreen():void
    {
    if (stage.displayState == StageDisplayState.NORMAL) {
    stage.displayState=StageDisplayState.FULL_SCREEN;
    } else {
    stage.displayState=StageDisplayState.NORMAL;
    }
    }
    stage.addEventListener(Event.ENTER_FRAME, _handleEnterFrame)
    function _handleEnterFrame(event:Event):void
    {
    goFullScreen();
    }

    Just make sure that you stop your Flash movie from looping around or it will loop around and keep trying to full screen or un-full screen

  6. May 28, 2008 at 3:43 am | #6

    I need help. I placed this code in the first frame of the .fla for a swf file, modified the HTML so that if allowed fullscreen automatically without having to click anything. I must be missing something. I appreciate whatever suggestions you may offer.

    My understanding on this code is that I don’t need to place this on the flvplayback. It should open the whole page (swf file) fullscreen. I have an walkon host .flv (alpha channel video) buried down in the file.

  7. May 28, 2008 at 6:11 pm | #7

    I tried every which way to get the Flash movie to go full screen automatically today and I don’t think it’s possible. It appears to only work when a user action occurs.

  8. May 28, 2008 at 10:49 pm | #8

    Hey alpha guy,

    You won’t be able to achieve exactly what you are looking to do….

    “The ActionScript that initiates full-screen mode can be called only in response to a mouse click or keypress. If it is called in other situations, it will be ignored (in ActionScript 2.0) or throw an exception (in ActionScript 3.0).”

    Sorry :(

  9. Chris
    June 1, 2008 at 9:49 pm | #9

    Thanks for this post Bmorrise, it was really helpful & easy to understand

    And to alphaguy, looks like Adobe just beta’ed you

  10. June 28, 2008 at 1:33 pm | #10

    Yes, it’s true that fullscreen can only be activated via user action. It is a security feature that Adobe implemented

  11. June 28, 2008 at 2:15 pm | #11

    One problem with fullscreen mode is that all your widgets enlarge as well. To achieve something like Youtube’s fullscreen, add this line and then manually scale the appropriate items:

    stage.scaleMode=”noScale”;

  12. archana
    June 29, 2008 at 6:34 am | #12

    pls some can help me in getting full screen for swf file which code should i use pls some plssss help me out very urgentttt

  13. Anonymous
    July 2, 2008 at 4:18 pm | #13

    I think there

  14. Anonymous
    July 16, 2008 at 10:32 pm | #14

    I found another tutorial on this subject which might make it easier for the beginners – its step by step

    http://www.bezzmedia.com/swfspot/tutorials/flash8/True_Fullscreen_Flash_Mode

  15. Piter
    August 1, 2008 at 6:49 am | #15

    anyone know how to set flash .exe file fullscreen on vista OS ?

  16. August 12, 2008 at 4:19 pm | #16

    Nice tutorial. I really like the as3 way of working.

  17. Christelle
    September 17, 2008 at 1:27 am | #17

    Hi, ok it’s perfect!
    But now everytime i click on a button or a pic or something, it goes fullscreen to un.
    Help plz :(

  18. Christelle
    September 17, 2008 at 1:28 am | #18

    to The person who wrote that msg:

    “I found another tutorial on this subject which might make it easier for the beginners – its step by step

    http://www.bezzmedia.com/swfspot/tutorials/flash8/True_Fullscreen_Flash_Mode

    Anonymous said this on July 16, 2008 at 10:32 pm ”

    it works onlt for AS2

  19. September 18, 2008 at 9:58 am | #19

    GREAAAAAAAAAAAAAAAAAT!!! Thanks a lot! It helped me making this website : http://www.renauddejeneffe.com

    Thank you a lot!

  20. Kevin
    October 15, 2008 at 1:37 pm | #20

    Awesome tutorial. I just altered the code a little so a button activated the full screen instead of the stage. Thanks for setting this up.

    Great job.

    • Gary
      June 11, 2009 at 8:52 am | #21

      I know very little about AS, so how did you modify the code to get it to work with just a single button.

      • June 11, 2009 at 9:48 am | #22

        To make it work with a button you’ll need to give the button and id and then change this line:

        stage.addEventListener(MouseEvent.CLICK, _handleClick)

        and replace ’stage’ with whatever the id you gave the button.

        hope this helps,

        bmorrise

  21. October 29, 2008 at 3:31 am | #23

    just what i’ve been looking for. great!

  22. Musuemgirl
    October 30, 2008 at 8:21 am | #24

    How do you get the Flash movie to stop looping between full screen or un-full screen?

  23. MuseumGirl
    October 30, 2008 at 8:22 am | #25

    How do you get the Flash movie to stop looping between full screen or un-full screen?

  24. FlashNewbie
    November 18, 2008 at 10:34 pm | #26

    How would you use the embed params if you’re using SWFObject to embed the swf?

  25. November 19, 2008 at 12:18 pm | #27

    Hi,
    it works perfect until I put a video with flv playback with a button over the video. Works in flash if i do ctr+enter but in the swf the button stop works and don’t appears nothingt over the video.

  26. January 22, 2009 at 1:18 pm | #28

    Great tutorial, thanks!

    I am curious why stage is spelled lowercase and why if spelled uppercase Stage that the code will not compile properly.

    It’s odd because spelling stage with an uppercase s, i.e., Stage will display code-hints after typing a dot to add a property.

    stage. will not display code-hints in the Actions window.

    Stage. will display code-hints in the Actions window.

    I have always found this to be annoying as it is necessary to know the exact case of a method even though there aren’t methods that use both cases, that I’m aware of.

    I would appreciate it if you have an explanation.

    Thank you,
    Nathan

    • June 24, 2009 at 3:05 am | #29

      actually, “Stage” refers to flash.display.Stage. On the other hand, “stage” refers to this.stage (see flash.display.MovieClip) witch is the reference to the Stage object that contains the MainTimeline (the Document Class).

  27. Jimbo
    January 23, 2009 at 10:31 am | #30

    Hi !
    I got a problem… How do I get the formmail/contactform to work in fullscreen mode. When I exit fullscreen it works fine to input text in the form. But it do not work in Fullscreen mode :( thanks.. Jimbo

  28. Bob
    January 26, 2009 at 3:57 pm | #31

    Nathan,

    Stage -> class type
    stage -> instance of type

    You can create your own Stage instance:

    var mySpritesStage:Stage = mySprite.stage;

    note that mysprite.stage is returning an actual instance of a Stage object, whereas simply referring to Stage is referring to the type, Stage.

    Hope that helps.

  29. Bob
    January 26, 2009 at 4:11 pm | #32

    Also, so that you could have global access to the root DisplayObjectContainer, and still be able to have a Stage type, they needed to name it something different than Stage to avoid conflicting names, which makes stage an understandable choice. This is similar in some ways to AS2’s _root property.

  30. Bob
    January 26, 2009 at 5:54 pm | #33

    Jimbo,

    In flash help under the Stage.displayState entry it says:

    “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).”

    Sorry.

  31. February 4, 2009 at 7:57 pm | #34

    Thanks for that code line
    stage.scaleMode = StageScaleMode.NO_SCALE;

    I was really looking for that and couldn’t recall it my self. Thanks for this “hint”.

  32. Brent
    March 9, 2009 at 10:34 pm | #35

    For flash embedded into a website StageDisplayState.FULL_SCREEN cannot be called automatically, therefore it must be linked to a button. Also forms do not work in fullscreen mode. These are for security/anti spam reasons.

    Eg, how would you like it if a website popped up a window with fullscreen ads all the time without you clicking anything, I’m sure you’d get annoyed very quickly :)

  33. Paulo
    March 19, 2009 at 12:20 pm | #36

    Hi Everyone… I did manage to get the fullscreen to work on a panoramic tour i am creating for a university project but it does not do full screen on the stage. It is working as it if just removed the borders of the browser… it does the full screen but does not scale the stage to fit the whole screen with image…. can you please help me????????

    I really need this…

    Thanks

  34. Brent
    March 19, 2009 at 4:38 pm | #37

    Sounds like you’ve got your stage scaleMode set to noScale.

    Heres a link to the docs for it:
    http://www.adobe.com/livedocs/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002694.html

    if you set:
    stage.scaleMode = “showAll”;

    then you should be ok :) There’s also a bunch of other ones you can try like “noBorder” and “exactFit” that might be worth trying to get the desirable effect.

  35. April 14, 2009 at 2:19 am | #38

    That’s awesome thank you so much :-)

  36. Justin Moser
    September 15, 2009 at 5:51 am | #39

    everytime I use this code, when i test the movie i get an error code saying:

    1046: Type was not found or was not a compile-time constant:
    MouseEvent.

    Source: function _handleClick(event:MouseEvent):void

    any reason for this? I have a movie clip with an instance name of “fullscreen” then replaced “stage” in:

    “stage.addEventListener(MouseEvent.CLICK, _handleClick)”

    with that instance name.

    I am doing a fluid layout where the movie clips are not on the stage but loaded via an external .as file from the library onto their co-ordinates on the stage.

    This code does not seem to work at all for me. anyone know why?

  37. Brent
    September 15, 2009 at 5:57 am | #40

    When you’re compiling it doesn’t know what the mouse event is so you need to import it.

    in your external .as file at the top put:

    import flash.events.MouseEvent;

    or

    import flash.events.*;

    if you want to import the whole package

  38. Justin Moser
    September 15, 2009 at 6:05 am | #41

    Thanks Brent,
    I added that line to the package import text under the lines that import the fluid layout, and im still getting the same error message :S

    really doesnt seem to like that one line of code..

    • Brent
      September 15, 2009 at 6:07 am | #42

      if you email it to foolio0_o at hotmail.com then i will take a look for you.

      • Justin Moser
        September 15, 2009 at 6:08 am | #43

        Thankyou very much :)

      • Justin Moser
        September 15, 2009 at 6:20 am | #44

        Ive emailed it to that address..you should recieve it from justin at baysickdesign.com

        Thanks again!

      • Brent
        September 15, 2009 at 6:21 am | #45

        Yup got it, all fixed just sending the reply now, the problem was with the class structure :)

      • Justin Moser
        September 15, 2009 at 6:29 am | #46

        ah thanks so much! lifesaver! Ill keep checking for it! :D :D

  39. September 30, 2009 at 12:15 am | #47

    hey, nice info, this really helped med a lot :O)

    check out my own result here:
    http://www.campjohn.dk/wp/?p=1163

  40. Bean
    September 30, 2009 at 6:48 pm | #48

    Hi

    im trying to make a swf call another swf and then go full screen, i can get the swf to call in the other ok, but then i cant make it go full screen, is there a way i can link this full screen to the button that calls the external swf so it calls it and sets the whole thing to full screen ?

    Thanks

    Bean

  41. Catherine
    November 3, 2009 at 4:16 pm | #49

    I’m needing the same help as Bean. Thanks!

  1. October 17, 2008 at 2:58 pm | #1