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>
Categories: ActionScript 3, Basics, Flash CS3, Functions, full screen
ActionScript 3, Flash CS3, full screen


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.
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.
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?
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
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
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.
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.
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
Thanks for this post Bmorrise, it was really helpful & easy to understand
And to alphaguy, looks like Adobe just beta’ed you
Yes, it’s true that fullscreen can only be activated via user action. It is a security feature that Adobe implemented
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”;
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
I think there
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
anyone know how to set flash .exe file fullscreen on vista OS ?
Nice tutorial. I really like the as3 way of working.
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
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
GREAAAAAAAAAAAAAAAAAT!!! Thanks a lot! It helped me making this website : http://www.renauddejeneffe.com
Thank you a lot!
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.
I know very little about AS, so how did you modify the code to get it to work with just a single button.
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
just what i’ve been looking for. great!
How do you get the Flash movie to stop looping between full screen or un-full screen?
How do you get the Flash movie to stop looping between full screen or un-full screen?
How would you use the embed params if you’re using SWFObject to embed the swf?
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.
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
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).
Hi !
thanks.. Jimbo
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
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.
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.
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.
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”.
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
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
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.
That’s awesome thank you so much
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?
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
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..
if you email it to foolio0_o at hotmail.com then i will take a look for you.
Thankyou very much
Ive emailed it to that address..you should recieve it from justin at baysickdesign.com
Thanks again!
Yup got it, all fixed just sending the reply now, the problem was with the class structure
ah thanks so much! lifesaver! Ill keep checking for it!
:D
hey, nice info, this really helped med a lot :O)
check out my own result here:
http://www.campjohn.dk/wp/?p=1163
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
I’m needing the same help as Bean. Thanks!
hello .. same here I need same help as soon as possible please
thanks in advance