Creating full-screen Flex applications

by Peter deHaan on August 7, 2007

in FullScreen, FullScreenEvent, StageDisplayState

Here is a quick post on using Flash Player 9’s Full-Screen Mode in Flex. I’ve seen this appear a few times in the bugbase and on lists, but here is some simple code to let you toggle between “full screen mode” and “normal mode” in a Flex application. Note that in this example I’m listening for the applicationComplete event in the main <mx:Application /> tag instead of the creationComplete event. The applicationComplete tag is called slightly after the creationComplete event, after the Application has been completely initialized.

If you try and access the Application.application.stage property from the creationComplete event, you’ll get a run-time error (RTE) saying the following:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at main/init()
at main/___main_Application1_creationComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/doPhasedInstantiation()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()
at mx.core::UIComponent/callLaterDispatcher()

The example below is pretty bare with just a few Label controls and a Button control, but it should have enough of the required code to give you a push in the right direction.

Full code after the jump.

You must have version 9,0,28,0 or greater of Flash Player installed to use full-screen mode. Download the latest version of Adobe Flash Player.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/07/creating-full-screen-flex-applications/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init(event)">

    <mx:Script>
        <![CDATA[
            import flash.display.StageDisplayState;

            private function init(evt:Event):void {
                /* Set up full screen handler. */
                Application.application.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
                dispState = Application.application.stage.displayState;
            }

            private function fullScreenHandler(evt:FullScreenEvent):void {
                dispState = Application.application.stage.displayState + " (fullScreen=" + evt.fullScreen.toString() + ")";
                if (evt.fullScreen) {
                    /* Do something specific here if we switched to full screen mode. */
                } else {
                    /* Do something specific here if we switched to normal mode. */
                }
            }

            private function toggleFullScreen():void {
                try {
                    switch (Application.application.stage.displayState) {
                        case StageDisplayState.FULL_SCREEN:
                            /* If already in full screen mode, switch to normal mode. */
                            Application.application.stage.displayState = StageDisplayState.NORMAL;
                            break;
                        default:
                            /* If not in full screen mode, switch to full screen mode. */
                            Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;
                            break;
                    }
                } catch (err:SecurityError) {
                    // ignore
                }
            }
        ]]>
    </mx:Script>

    <mx:String id="dispState" />

    <mx:Label text="width={Application.application.width}" />
    <mx:Label text="height={Application.application.height}" />
    <mx:Label text="displayState={dispState}" />

    <mx:Button label="Toggle fullscreen" click="toggleFullScreen()" />

</mx:Application>

View source is enabled in the following example.

For more information on Full Screen Mode in Flash Player 9 (ActionScript 2.0 and ActionScript 3.0) check out the following article on the Adobe Developer Center: “Exploring full-screen mode in Flash Player 9″.

I *knew* I would have forgotten something. The real trick to using FullScreen support is to enable it in the JavaScript embed code, or <object /> and <embed /> tags… So, in your HTML wrapper, add the following property:

AC_FL_RunContent(
    "src", "main",
    "width", "100%",
    "height", "100%",
    "align", "middle",
    "id", "main",
    "quality", "high",
    "bgcolor", "#869ca7",
    "name", "main",
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer",
    "allowFullScreen", "true"
);

Or, if you are using <object /> and <embed /> tags, you can use the following syntax instead:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        id="main" width="100%" height="100%"
        codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
        <param name="movie" value="main.swf" />
        <param name="quality" value="high" />
        <param name="bgcolor" value="#869ca7" />
        <param name="allowScriptAccess" value="sameDomain" />
        <param name="allowFullScreen" value="true" />

    <embed src="main.swf" quality="high" bgcolor="#869ca7"
        width="100%" height="100%" name="main" align="middle"
        play="true"
        loop="false"
        quality="high"
        allowScriptAccess="sameDomain"
        allowFullScreen="true"
        type="application/x-shockwave-flash"
        pluginspage="http://www.adobe.com/go/getflashplayer">
    </embed>

</object>

Also, I just learnt from my co-worker Raghu’s blog (“FLEXing My Muscle” and his “Error on adding FullScreenListener in creationComplete handler” post) that you can use the SystemManager class instead of all my references to Application.application. Thanks Raghu!

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/07/creating-full-screen-flex-applications/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init()">

    <mx:Script>
        <![CDATA[
            import flash.display.StageDisplayState;
            import mx.managers.SystemManager;

            private function init():void {
                /* Set up full screen handler. */
                systemManager.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
                dispState = systemManager.stage.displayState;
            }

            private function fullScreenHandler(evt:FullScreenEvent):void {
                dispState = systemManager.stage.displayState + " (fullScreen=" + evt.fullScreen.toString() + ")";
                if (evt.fullScreen) {
                    /* Do something specific here if we switched to full screen mode. */
                } else {
                    /* Do something specific here if we switched to normal mode. */
                }
            }

            private function toggleFullScreen():void {
                try {
                    switch (systemManager.stage.displayState) {
                        case StageDisplayState.FULL_SCREEN:
                            /* If already in full screen mode, switch to normal mode. */
                            systemManager.stage.displayState = StageDisplayState.NORMAL;
                            break;
                        default:
                            /* If not in full screen mode, switch to full screen mode. */
                            systemManager.stage.displayState = StageDisplayState.FULL_SCREEN;
                            break;
                    }
                } catch (err:SecurityError) {
                    // ignore
                }
            }
        ]]>
    </mx:Script>

    <mx:String id="dispState" />

    <mx:Label text="width={Application.application.width}" />
    <mx:Label text="height={Application.application.height}" />
    <mx:Label text="displayState={dispState}" />

    <mx:Button label="Toggle fullscreen" click="toggleFullScreen()" />

</mx:Application>

{ 96 comments… read them below or add one }

1 subbu June 9, 2008 at 1:49 am

Is it possible fullscreen mode in flex apllication?If it is yes plz suggest how to write the full screen mode application…

Reply

2 Dylan Oliver July 2, 2008 at 4:00 pm

The code above got me started but this uses a getter/setter on fullScreen:Boolean to allow you to enter fullscreen mode with “fullScreen=true” and bind to the value of fullScreen, as I do below with the checkbox:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
  <mx:initialize><![CDATA[
  systemManager.stage.addEventListener(
    FullScreenEvent.FULL_SCREEN,
    function(event: FullScreenEvent): void {  fullScreen = event.fullScreen; }
  );
  ]]></mx:initialize>

  <mx:Script><![CDATA[
  private var _fullScreen: Boolean;
  [Bindable] public function get fullScreen(): Boolean { return _fullScreen; }
  public function set fullScreen(isFull:Boolean):void {
  _fullScreen = isFull;
  stage.displayState = (isFull) ? StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL;			}
  ]]></mx:Script>

  <mx:CheckBox id="fs" label="Full Screen"
    click="fullScreen=event.target.selected" selected="{fullScreen}"
    horizontalCenter="0" verticalCenter="0"/>

</mx:Application>

Reply

3 Boaz July 5, 2008 at 1:20 pm

Peterd,
i saw you answered that the Keyboard events are disable in full screen mode,
can you tell why? is it going to be solved soon? test is the name of the game
in RIA…
Boaz

Reply

4 Philippe Schlier August 21, 2008 at 10:02 am

Hello,
I’m new on Flex but from what I read, the Full screen mode doesn’t allow text input nor switching tab. This is a show stopper for me. Is there a way of going around those restrictions ? Instead of Flex’s full screen mode, I could use a browser full screen but how to trigger a F11 keystroke on the browser from a Flex link ?

Happy Flex
Philippe

Reply

5 MechanisM August 27, 2008 at 4:26 pm

how to add fullscreen here:

<script type="text/javascript">
        // <![CDATA[
            var so = new SWFObject('MechanisM.swf', 'website', '100%', '100%', '10', '#000000');
            so.useExpressInstall('swfobject/expressinstall.swf');
            so.write('content');
        // ]]>
        </script>

Reply

6 peterd August 27, 2008 at 5:25 pm

MechanisM,

I’ve never tried SWFObject, but does something like this work?

<script type="text/javascript">
// <![CDATA[
   var so = new SWFObject('MechanisM.swf', 'website', '100%', '100%', '10', '#000000');
   so.addVariable("allowFullScreen", "true");
   so.useExpressInstall('swfobject/expressinstall.swf');
   so.write('content');
// ]]>
</script>

Peter

Reply

7 Hossein November 13, 2009 at 10:05 am

so.addParam() worked for me.
so.addVariable() passes the variables to the flash application itself.

Reply

8 MechanisM August 29, 2008 at 7:47 pm

Thnxx Peterd!!!

Reply

9 Steve W September 4, 2008 at 3:24 pm

Peter,

Is there any work being done to enable full functionality (e.g. text input) in the full screen mode? Without this capability, it’s not good for much more than a video player or statis charting application. Supposedly there is some security concern, but it needs to be up to the developer/client to decide (fullScreenInteractive = “true”).

Reply

10 penpen September 4, 2008 at 7:23 pm

很好,很强大

Reply

11 Andrea September 6, 2008 at 1:03 pm

Great post Peter,
but I’m guessing at text input problem.
I totally got lost trying to find a work around..

any advice?

thank you,
andrea

Reply

12 peterd September 6, 2008 at 7:18 pm

Andrea,

Text input is currently not supported while a Flash/Flex application is in full screen mode in Flash Player.

Peter

Reply

13 Yaba September 9, 2008 at 8:14 am

“Text input is currently not supported while a Flash/Flex application is in full screen mode in Flash Player.”

And hopefully will never be. Consider a page that renders a full screen flex window showing a standard Windows log in screen. How many will think that something weird has happened to Windows once again and enter the login credentials into the malicious window?

Reply

14 Magz September 17, 2008 at 2:21 pm

Hey!

Is it possible for an AIR application to have two stages which go fullscreen on two monitors with different content? I would like a movie on full screen on my secondary display and controls on the other, both in fullscreen. This would really help me out, thanks!

Reply

15 peterd September 18, 2008 at 7:55 am

Magz,

I’m not aware of any APIs that allow you to do that (but I’m certainly no AIR expert). Maybe try asking on a high-traffic list like FlexCoders and see if anybody has tried experimenting with AIR + full screen + dual monitors.

Sorry,
Peter

Reply

16 smacks October 15, 2008 at 9:13 am

Very good work great thx for this great tutorial !!!

Reply

17 Falco Stellare October 24, 2008 at 5:27 am

In AIR you can use the FULL_SCREEN_INTERACTIVE statement to go fullscreen with working text inputs. It could be nice to have this feature in Flex too. I undestand all the security issues bond with this function, but I can’t believe that there is not a workaround in order to let us developers design a fully functional fullscreen application and at the same time let users keep their security safe.

At the current conditions, fullscreen feature in Flex is nothing more than an oddity, good just for poorly interactive web sites…

If this problem can’t be solved, I think I’ll abandone the Flex platform very quickly :-(((

Reply

18 Falco Stellare October 27, 2008 at 3:08 am

Adobe developers say that disabling text inputs when in fullscreen is a security feature: you cannot interact with a Flex application running fullscreen because a potential hostile could duplicate a login interface and stole your account, with a well-known phishing technique.

But did you noticed a funny thing? You can’t write directly into an input field in fullscreen mode, yes, but you can always <b>PASTE TEXT INTO IT</b> (right-click on the field, and then select “paste” from the popup menu) and thus completely bypass the clever and strong security “fullscreen feature”. No need for hacks, patches, or whatever. <b>Just copy a text from notepad and paste it into the “disabled” input field of your fullscreen Flex application</b>: oh my god, the disabled input field works again! Press your submit button, and go.

WOW!!! :-\

Dear Adobe developers, please, remove this silly limitation NOW, and try to deal with security issues in better ways. <b>Security through obscurity is nothing but a failure</b>, if you are a real software developer.

There are peoples here, who try to produce useful interactive applications with Flex (in my case, applications to be used for scientific research in oncology and molecular biology) and who really would like to take advantage from a fully working fullscreen feature…

And please, don’t suggest to switch to AIR, this is not a valid alternative if you’re developing an application to be distributed as a web service.

Reply

19 Simon November 3, 2008 at 4:01 pm

Hi,

I have a white screen when I insert “allowFullScreen”, “true”. The problem occur exactly if I insert this line. Any idea why, apparently, javascript don’t like this…

I use as well Cairngorm, locales, and external module but I don’t think it’s related ?

By the way I can run your example and I have the last player version.

Thanks
Simon

Reply

20 dbx166xl November 10, 2008 at 8:33 am

Via Flex 3, & Flash Player 10, editing the html template file produces a blank screen in Firefox 3. Anyone else having this issue? Thanks in advance!

Reply

21 Tiago December 22, 2008 at 2:19 pm

Pessoal eu não concegui realizar o teste ….
alguem poderia me ajudar ?

Eu clico no botão mas não acontece nada, eu ja abilitei o “allowFullScreen”, “true”
Teria como algeum me passar um video ou um projeto completo de exemplo?

Obrigado!

Reply

22 Tiago December 22, 2008 at 2:23 pm

I click on the button but nothing happens, I already enable the “allowFullScreen”, “true”
Algeum can I pass a video or complete a project as an example?

Thank you!

Reply

23 Bevsta December 27, 2008 at 8:22 am

Magz.. regarding your query.. I think WebOrb can potentially do this in a couple of ways.. one of which is to use shared objects to pass information between the 2 different browser instances or potentially stages, each of which could be hosting different content but effectively be communicating to be ‘one application..

Reply

24 tyler January 8, 2009 at 8:41 am

What if you have another swf inside of your flex app using fullscreen? It is a video player and I want to make the video player go fullscreen on click, but the whole flex app goes fullscreen. How do I capture that and tell flex to make that inside player be the thing that is FS?

Reply

25 Ewout February 18, 2009 at 3:13 am

Thanks for this great article. While trying to enable “automatic full screen” I encountered several security errors and found some solutions:

- From inside a browsers window you just can’t automatically switch to fullscreen; even when you dispatch a clickevent. It can only be triggered by a REAL clickevent.

- When compiled and exported to a projector (from within flashplayer) you actually CAN automate fullscreen and have textinputs etc. enabled (this last thing I did not test).

:)

Reply

26 Michael March 2, 2009 at 11:58 pm

Debugging Fullscreen applications in Flex Builder:

http://devote.your.life.auricom.com/?p=65

Reply

27 daniel March 3, 2009 at 7:01 pm

thank you for this great function;
i haven’t had time to read your post through; but i’m sure it’s very useful.
the code works; and was easy to add to a project.

thanks again and
please keep it up :P

Reply

28 daniel March 3, 2009 at 10:32 pm

@tyler: i think you can just stretch the video swf to the full screen size by making the flex app full screen and then directly after that; changing the video swf’s height and width properties to the same as full size of the screen / stage.

hth

Reply

29 lee probert March 5, 2009 at 8:57 am

@tyler I had this problem so what I did was create two Video containers, one of them sitting above everything else within a Box container with a black background and its visibility bound to a Boolean that represented the Fullscreen mode. When the video is playing you swap the NetStream from one Video container to the other. The result is a seamless bit of fullscreen video without the rest of the SWF content.

Reply

30 elDalai March 19, 2009 at 7:34 am

Hi!

i need to use in my FullScreen Application the ESCAPE key for navigation…

My cuestion is:

Could i disable o cancel the FullScreenEvent and use the KeyboardEvent.KEY_DOWN ? i need an only fullScreen App….

this.addEventListener(KeyboardEvent.KEY_DOWN, keyDownEventHandler);

}
private function keyDownEventHandler(event:KeyboardEvent):void {
switch(event.keyCode)
{
case Keyboard.ESCAPE: cancelAction();break;//never happends
case Keyboard.ENTER: goAction();break;
}
}

Thanks!

Reply

31 sam March 20, 2009 at 2:44 pm

keyboard disabled in full screen mode…

sam

Reply

32 Jon March 26, 2009 at 2:03 pm

Excellent site.

I went through the entire tutorial just to find out that my Flex application at Full Screen will not allow inputs. This is still the case after 1.5 years time, eh? Ouch.

I guess I’ll read all the comments before actually trying the code next time. A blurb at the beginning of the article could’ve saved me 30 mins though…

Reply

33 Jon March 26, 2009 at 2:11 pm

For more on why the Adobe crew decided to not allow user-input while in Full Screen mode:

http://livedocs.adobe.com/flex/3/html/help.html?content=05B_Security_06.html

Seems silly, but it’s the fastest solution to their security issue with full-screen.

Beginning code workaround… now.

Reply

34 Sundance May 14, 2009 at 12:46 pm

Hi! Theres any way to modify the wrapper file generated from Adobe Flex Builder? I hate to modify all the time the Full screen options. Thanks in advance

Reply

35 Sundance May 14, 2009 at 4:17 pm

I mean, theres a posibility to change automatically the content of the wrapper file on Flex IDE to make this fullscreen options available without modify the wrapper file by hand, beacose when you change the source the wrapper change too. Thanks and sorry for double post
Sun

Reply

36 Pankaj June 2, 2009 at 10:35 am

There is no place in the IDE in order to change or add params but you can go to the root folder of your project, and go into html-template and add these parameters in index.template.html and save the file.
This is a template html file, flex builder uses, in order to generate html wrapper file.

-Pankaj

Reply

37 Tahir Alvi June 3, 2009 at 11:58 pm

I am very thank full and for using this example, but i want to know that Videodisplay control is capable of full screen, or canvas or any other container except application.

It would be nice if any body send me the answer.

Reply

38 Jason August 3, 2009 at 8:23 pm

Full screen works when I try it by button click handler.
But it doesn’t work when tried from Timer handler or
even using button.dispatchEvent(new MouseEvent(MouseEvent.CLICK)).

Reply

39 Sergio Trujillo August 4, 2009 at 4:45 am

You can create a virtual keyboard in full screen mode, to get the user and password by mouse clicking.
It’s very simple to simulate Windows or Linux, with this virtual keyboard.
I don’t understand the limitation in the text input component…

Reply

40 Ramesh September 11, 2009 at 2:37 pm

Need help.

When I click on the example above, full screen works well. I copied this code and tried to run it on my computer, the full screen does not work. I edited the HTML to contain the fullScreen attributes. The page is empty. If I try and run the swf, the swf runs without fullScreen capability. I must be doing something simple wrong. Please help. Thanks

Reply

41 Tahir October 5, 2009 at 12:22 am

Very nice work.

Reply

42 Richard December 7, 2009 at 7:35 am

If you’re getting a blank screen after adding ‘ “allowFullScreen”, “true” ‘ into the html wrapper, make sure you’ve put a ‘,’ after the previous entry as it’s a list.

Looks like i wasn’t the only person to make this mistake :)

Reply

43 Jon Air December 8, 2009 at 3:05 am

We have a problem after coming out of full screen mode on IE that text inputs no longer work – like it isn’t properly exiting the security problems of being fullscreen.

Full details, along with a reward for solving this issue can be found here.

http://www.sparkol.com/ScreenProblem.html

Thanks for your help!

Reply

44 radha December 22, 2009 at 3:55 am

hi!!!

I am new to flex… and i am trying to write an application which displays albums of my friends which are pesent in my friendlist..
Kindly help…

Reply

45 Anon January 20, 2010 at 3:41 pm

I’ve also encountered the same problem Jon Air mentions. After switching a simple test application in and out of fullscreen mode twice, text inputs no longer work in non-full-screen mode after that.

This happens in IE but not in FireFox. It does not happen when I run the app locally within IE from within Flex Builder 3, either. The application only behaves like this when it is actually installed on my server.

Has anyone else encountered this bug? Jon Air’s link no longer works.

Reply

46 Shawn January 26, 2010 at 7:28 am

I don’t think it’s adobe engineers who decided to disable the keyboard in full-screen mode, usually such idiotic decisions come from the head hanchos, especially the ones graduated from India. If critical thinking comes critically hard than they should stay away from computing!!

If a site wants your login/password in full-screen mode they can still do that saying “Your keyboard is locked, please re-login using the virtual keyboard” and half the fools out there will fall for it.

Times like these motivate you to look at Silver Light!! Tell Shantanu Narayen to stop promoting idiots.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: