How to use fullscreen in AS3 | Stage Display State Tutorial

    fullscreen_tut png
    One of the best features of the flash player if you’re doing video is the fullscreen functionality. It has been a question I’ve heard repeatedly. There are limits to what you can do in fullscreen. Such as minimal keyboard support while in fullscreen. But it is perfect for a video player! Who doesn’t want to see a video expanded to full screen mode?

    There are a couple things to consider when coding fullscreen into your flash. Remember the hard coded “Press Esc to exit full screen mode.” that Adobe has placed into the flash player. This is untouchable by developers, and the function returns to normal stage display state. So we call the function to go fullscreen, but the exit fullscreen has already been written for us. This can pose a problem though, when we need the player to do something when we exit fullscreen, that is when we want it to do something more than the generic black box function adobe includes.

    Steps

    1. specify stage properties
    2. full screen button and listeners
    3. stage fullscreenEvent listener
    4. (functions for each)
    5. allowfullscreen = true

    Example

    Get Adobe Flash player

    1. Stage properties exist that allow us to specify what type of fullscreen we want.  We can have the swf scale to fit the fullscreen area (StageScaleMode.SHOW_ALL), not scale at all (StageScaleMode.NO_SCALE), skew to fit fullscreen (StageScaleMode.EXACT_FIT), and scale to fill fullscreen area (Stage.ScaleMode.NO_BORDER).  We may also edit the alignment of the stage in the fullscreen area; in this example I’m using TOP, but refer to documentation for more options

    2. Adobe has placed restrictions on when a swf can enter fullscreen, and has deemed that it must result from a user interaction, a mouse click or keystroke. So create your buttons (or keyListeners). I prefer to have one button to enter fullscreen and another to exit, and have them both call the same function to toggle fullscreen. It gives a clearer communication to the user. I then control the visibility of these buttons depending on the current display state of the stage.

    3. Another listener to watch the stage dispaly state. stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreenChange); This will fire every time the stage display state changes. We need this because as I mentioned earlier, when entering fullscreen we use our own function, but the ‘hit esc to exit fullscreen’ functionality is built into the flash player, we can’t update our stage layout or button visibility without watching to catch when the display state is changed. Using this method we can update our stage layout any and every time.

    4. Of course flesh out the fullscreenToggle function to include anything else you need.

    5. Lastly, for a SWF file embedded in an HTML page, the HTML code to embed Flash Player must include a ‘param’ tag and ‘embed’ attribute with the name ‘allowFullScreen’ and value ‘true’, like this:

    <object>
        ...
        <param name="allowFullScreen" value="true" />
        <embed ... allowfullscreen="true" />
    </object>

    The allowFullScreen tag enables full-screen mode in the player. If you do everything else right and don’t include this in your embed codes, fullscreen will not work. The default value is false if this attribute is omitted. Note the viewer must at least have Flash Player version 9,0,28,0 installed to use full-screen mode. Also note that  the simple (ctrl + enter) testing your movie in flash will not allow fullscreen either, you must use the debug tester (ctrl + shift + enter) … or go open the published swf in flash player.

    Actionscript

    stage.scaleMode = StageScaleMode.SHOW_ALL;
    stage.align = StageAlign.TOP;

    var stageDisplayAdjustCounter:uint = 0;

    fsb.addEventListener(MouseEvent.CLICK, fullscreenToggle);
    ssb.addEventListener(MouseEvent.CLICK, fullscreenToggle);
    stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreenChange);

    fsb.buttonMode = true;
    ssb.buttonMode = true;

    //fullscreen buttons need this to adjust the stage display state.
    //pressing escape to exit fullscreen bypasses this function
    function fullscreenToggle(e:MouseEvent = null):void {
    status.appendText(stageDisplayAdjustCounter+". fullscreenToggle from "+stage.displayState+"\n");
    //normal mode, enter fullscreen mode
    if (stage.displayState == StageDisplayState.NORMAL){
    //set stage display state
    stage.displayState = StageDisplayState.FULL_SCREEN;
    }
    //fullscreen mode, enter normal mode
    else if (stage.displayState == StageDisplayState.FULL_SCREEN){
    //set stage display state
    stage.displayState = StageDisplayState.NORMAL;
    }
    //here we subtract 1 from the counter because it has already incremented (in onFullscreenChange) when we set the display state above

    status.appendText((stageDisplayAdjustCounter-1)+". fullscreenToggle to "+stage.displayState+"\n");
    status.scrollV = status.maxScrollV;

    }

    //this function is called every and anytime the stage display state is adjusted
    //either by pressing our buttons or
    function onFullscreenChange(e:FullScreenEvent = null):void {
    status.appendText(stageDisplayAdjustCounter+". onFullscreenChange\n");
    status.scrollV = status.maxScrollV;
    if (stage.displayState == StageDisplayState.FULL_SCREEN) {
    fsb.visible = false;
    ssb.visible = true;
    }
    else {
    fsb.visible = true;
    ssb.visible = false;
    }

    stageDisplayAdjustCounter++;
    }

    onFullscreenChange();

    Source

    Download fullscreen_tut.fla file

    This entry was posted in tutorial and tagged , , , , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

    8 Comments

    1. epic
      Posted April 23, 2009 at 4:50 am | Permalink

      thanks for the tutorial! it’s perfectly explained… you really helped me a lot! :)

    2. Russ
      Posted May 3, 2009 at 8:39 am | Permalink

      I have been looking for a tut on this, I couldn’t download the sample though.

    3. wako
      Posted June 25, 2009 at 7:44 am | Permalink

      thanks mate will try this later….

    4. Kyle
      Posted September 27, 2009 at 3:39 am | Permalink

      This helped me a ton very late one night when I was really struggling with something. Thanks a lot!

    5. Posted January 14, 2010 at 6:07 am | Permalink

      Thanks, This works. Awesome

    6. Anton Cherry
      Posted January 29, 2010 at 10:56 pm | Permalink

      Thanks Thanks Thanks very very very much!!!

    7. EDi
      Posted February 17, 2010 at 3:57 am | Permalink

      Thanks a lot your download and tut work for me alot!!!!!!!!!

    Post a Comment

    Your email is never published nor shared. Required fields are marked *

    *
    *

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

    • Recent Posts

      WordPress updates plugin directory

      New additions to the plugin directory include: favorites, incorporating support forums into it's own tab for each plugin as well as support stats being displayed! Great! I think we also need the ability to give plugins ratings and reviews (bonus points if it can be done from within a wordpress admin dashboard when installing plugins). [...]

      Short Head

      Use zipf's short head to tune your website rather than redesign the whole thing. To make a website successful it needs to meet the needs of the users. Find out what those needs are by using the short head philosophy to equate most searched things as the biggest needs of the users. Use personas to [...]

      Img Set?

      Great article at a list apart discusing the state of the industry regarding responsive images. This picks apart the set attribute of the img element from a surprisingly objective view coming from someone so close to the picture element. Insightful discussion about the principle behind the proposals than the actual solution too. If the working [...]

      Triudo

      A mesmerizing animated triangle-ish shape form. Embedded Link triduo triduo Tweet

      Git – the paradigm shift

      A great developer story about the differences on what Git is vs other version control and what Git is not. This is how we should learn it. I heard over and over that it was distributed, but never grasped what that meant, so here are a few links and explanations that will help unlearn version [...]

      Tweening Lib comes to Javascript!

      I'm very excited to share the news that the tween library from GreenSock (hands down the best tweening library I used in flash) is not ported for use in javascript! This will be great! I missed that simple syntax from as3 when animating javascript, and now I can have my cake and eat it too. [...]

      Responsive CSS Tricks

      Here are a few useful css tricks to remember when building responsive design sites from web designer wall Embedded Link 5 Useful CSS Tricks for Responsive Design Making the design to be responsive is very easy as shown in my Responsive Design in 3 Steps tutorial, but maintaining the elements to look aesthetically balanced on [...]

      Picture element of srcset attribute?

      Bruce details the reasons and story behind the srcset attribute which is now introduced as an alternative to the picture element. Some aspects of the attribute are nice (like the fact that it's an attribute and not a new element, so it's creating up new elements with for problems. It's adapting currently used elements to [...]

      SVG Preloader with Raphael JS

      Here's a very creative use of using a newly available technology. Using svg graphics which are very lightweight, for a website preloader. I like the animation used as well. Embedded Link Make a stylish preloader with SVG | Tutorial | .net magazine Many sites neglect users with slow connections. Ian Culshaw explains how to use [...]

      CSS3 Button/Icon set

      I've been secretly hoping to see a few of these pop up once the whole icon font idea spread through the nets. I really like this idea and it's a very nice implementation too! I only see some quality issues on a couple of the icons (such as youtube), but it's awesome and I hope [...]

    • Recent Comments

      Bruce Brownlee

      Bruce Brownlee

      Ah IE6. I'd have 2 more years of sleep without IE6. Margin doubling, no properties,...
      versaena

      versaena

      how to give color at runtime…… thank you
      Mobile Websites

      Mobile Websites

      I disagree, mobile websites are the future – desktop websites and mobile websites...
      Matt Fasick

      Matt Fasick

      That's cool. I like the ripple effect as well.
      Nico

      Nico

      hi! really great job guy! very impressive.. just a question… do u have a solution to do a refresh...
      Evan Mullins

      Evan Mullins

      Agreed! I've just seen some people get pretty heated about separating all functionality...