Fullscreen Flash With Browser Scrollbars

Tagged as: Flash, HTML & CSS, JavaScript

Title Edit: 08.22.07. I don't know what I was thinking, initially titled "...HTML Scrollbars", that doesn't make sense.

Update: 04.23.08. Working with Matthew Ellis , who commented below, I think we resolved the crashing issue with Firefox / Mac by removing ( commenting the code ) the constant updates sent from JavaScript to the SWF, these were mainly used for visual display.  The 'Updated Example' link has been updated to reflect these changes.

A brief introduction as to why this might be needed. At work we do quite a few video "mini-sites" for college recruiting purposes. It's a way to showcase the school to prospective students through the eyes of current students. These sites are primarily video driven, there is usually very little content outside of the videos other than links, possibly little fun facts etc.

Although we highly recommend transcripts of the video through closed captioning or html content for screen readers, this isn't always accepted as it drives up cost, unfortunately, but that is another subject / post entirely.

These sites tend to be full-on Flash sites that can stand alone but are still branded, they live outside of the main campus website and are associated with some form of campaign, mailer or opt-in initiative. As such the design usually calls for a centered, fullpage ( 100% width / 100% height ) Flash movie. The problem that tends to crop up with this approach is if you design for 800 x 600 or 1024 x 768 the site will always get passed to someone's grandmother who's screen resolution is set to 640 x 480 where the Flash movie extends beyond the borders of the browser, but since our Flash movie is set to 100% width and height our browser scrollbars are non-existant.

Now if the designer has the forethought to realize this and designs a flexible layout, you as the developer, can manage, scale and place the content within the "Stage" limits when the browser is resized using Flash's Stage.onResize handler. This isn't always the case. Please note, this all comes from a developers standpoint, where I get approved designs when it's time to start building. I am not always privy to designs before they goto the client for approval. I'm usually working on a project while the next one is getting worked, conceptualized and designed, I may be asked questions from time to time but i'm often given files and told to run with it, make it bouncy and fun.

You can also create scrollbars within Flash that "stick to the edges", this can be cumbersome and slow if you have alot of textual content, I have done this in the past and actually do this with my Portfolio, but it just doesn't feel right.

So as a proof of concept, let's imagine we have a Flash movie that has multiple sections and each section has a different layout and size but must stay centered on screen.

  • We need to have Flash call a JavaScript method that sets the movie width and height.
  • We need to have a JavaScript method that checks the width and height of the set Flash movie dimensions on browser resize and act accordingly.
  • We need to allow scrollbars or overflow in the event the user doesn't have Flash and see's our alternate content, but remove them in the event they have the proper version of Flash.

Again, this is proof of concept, so the "flashcontent" div is hardcoded into the JavaScript file. We will also use External Interface to call JavaScript methods from Flash and receive a notification from JavaScript telling us the size of the browser window when it's resized so we can display it within Flash, but only for testing purposes ( this may be what caused my friends browser crash with Firefox on the MAC ).

When the Flash file loads up, we have an initial handshake between Flash and Javascript, passing the width and height of the container within the Flash movie.

ExternalInterface.call( "initialize", container._width, container._height );

Now anytime we resize our container or change views we need to update our JavaScript file with the new width / height requirements of our Flash movie using, setFlashDimensions:

ExternalInterface.call( "setFlashDimensions", container._width, container._height );

The JavaScript file and CSS will do the rest for us. If the container width or height fall outside the bounds of the browser we make the 'flashcontent' div use pixels, if the Flash movie has enough room to breathe within the browser we set it back to 100%.

I've tested this on
PC:

  • IE 6 / 7
  • Firefox 2.0.0.6
  • Opera 9

MAC:

  • Safari
  • Firefox

A friend said it crashed Firefox on his Mac but I couldn't replicate.

In this example I am calling "setDimensions" repeatedly as the Flash stage is resizing because IE on PC seems to update the browser and dimensions while dragging the window, Firefox will not until you stop dragging the corner of the browser window.

Also in Firefox if you drag the browser window small enough as to align the Flash movie to the top left then start increasing the window size again, the Flash movie will stick at 0,0 for an instance.

Please note, I have not used this in a production environment, this is mainly a proof of concept. If I ever get around to testing it properly and making it a little easier to implement I will definetely post it here.

Here is a simple working example, click the orange box to change it's dimensions.

Download a working example here: Updated Example.

I use SWFObject exclusively and it seems like Geoff Stearns, creater of SWFObject and Bobby van der Sluis, creator of UFO, have teamed up to create the next generation of Flash detection, SWFFix. What i'd really love to see in SWFFix is a min-height / min-width setting.

Posted by Ben on August 22nd, 2007 at 6:54 am

Yeah this crashed my browser almost immediately (Firefox 2.0.0.6 Mac OS X 10.4.10)

Posted by Ken on November 14th, 2007 at 7:11 am

hi there, I tried downloading the source file, but it says “Unexpected file format” when I tried to open it in Flash 8…

Posted by Duncan on November 14th, 2007 at 11:13 am

Aye, sorry about that Ken. Your the second person who brought that to my attention. Been a busy few months. I saved the FLA as Flash 8 and re-uploaded.

Posted by Mark on December 8th, 2007 at 11:07 pm

Awesome… worked just the way I wanted. THANK YOU!

Posted by vDiaz on February 4th, 2008 at 9:33 am

I’m looking to achieve a similar effect with the scrollbar as you did in your portfolio. Is there any possibility you may be able to share your solution or point to somewhere where I can get some code samples. Thanks!

Posted by Duncan on February 5th, 2008 at 9:52 pm

Hi vDiaz, I have gotten a few requests for this and I’m usually hesitant about sharing things like this because it’s definitely not something you just plug in nor is it feature complete and I won’t be able to offer much help or support. Please don’t mis-understand, I’m all about sharing but it’s just something I threw together for myself quite some time ago, there are very few comments and I will say, I’m not overly proud of it.

So to the others who have inquired I do apologize, life has been hectic with work and family, I would like to eventually take this further and make it easier to implement, if I do I will definitely post it here.

One thing to note, if you have masked content in the MovieClip that is used by the scroller it will reflect the scrollable area, example; if your content is 2000px wide and your mask is 500px wide the scrollbars judge the width of the overall content as 2000px. Rather large gotcha but I couldn’t find a way around it.

Hope this will be of some help, click the box to resize the content…

ScrollTest Example

Posted by vDiaz on February 15th, 2008 at 10:57 am

Hey D, Thanks for the file.

Posted by vDiaz on February 15th, 2008 at 11:37 am

Duncan, I just realized that this was coded in AS2. Any idea wheer I can find an AS3 version. I’m actually working with your original post on this page.

Thanks,

Vic

Posted by Matt Ellis on April 9th, 2008 at 11:06 am

Hi, Yeah, this crashed FireFox (2.0.0.13) for me on my Mac (10.5.2)
Any ideas why this might be happening? This is the BEST fullscreen scrollbar apart from the fact it’s crashing FF! Any help would be greatly appreciated!

Posted by gee on June 26th, 2008 at 5:23 pm

best thing ever.

Posted by machinewashed on July 26th, 2008 at 10:22 am

Any chance you are planning on converting this to ActionScript 3.0?

Posted by Duncan on July 27th, 2008 at 9:21 pm

I think I would like to but at the moment, actually, I have been swamped for a while between day job and freelance, as I’m sure is pretty apparent if you’ve noticed the number of postings on this blog. So if I do get some downtime or a project that calls for it i’ll definitely post it here and also let you know.

Posted by Adam on September 19th, 2008 at 9:35 am

Is there a limit on how much height there can be in safari? I was doing a long list and it seems that everything is cut off at 4000…

Posted by Duncan on September 22nd, 2008 at 1:44 pm

Hi Adam,

Apparently there is. I setup 2 quick tests, 4000px height, and 4500px height. Seems as though MovieClips will not render past 4000 pixels but as you’ll notice the textfield at the bottom runs to the height of the stage and is visible. Seems to be a Flash thing, I tested this in Firefox 2.0.1. Found more information here: FI Blog. Not the simplest solution but a workaround nonetheless.

Posted by Biofundelfido on December 1st, 2008 at 10:31 pm

Пост хороший удачный, добавлю сайт в избранное.

Posted by AtronyHor on December 7th, 2008 at 7:56 pm

В каком-то блоге я уже встречал аналогичную информацию, но все равно спасибо

Posted by Dan on December 10th, 2008 at 5:20 pm

Hi Duncan!

How are you? My compliments for the great tutorial! A very nice one!

I have a question regarding clicking on the ‘mc’ to scale the ‘mc’ for the scrollbar to appear. How can I attach this script to several buttons, so when I click on one of the buttons, the scrollbar will extend or shorten according to the length of different ‘mc’s that would appear (when one of the buttons is activated).

Hopefully you can help me with it!

Thanks in advance!

Cheers, Dan

Posted by Paul Bryant on October 30th, 2009 at 1:52 am

Hi Duncan,
I’ve been searching for weeks for an AS2 fullscreen scroller that works with the MAC scroll wheel and the GAIA Flash Framework. I’ve downloaded your example “swfscroll”, but it doesn’t seem to work with the MAC scroll wheel. Any ideas?

Thank you very much.
Paul Bryant

Posted by Duncan on October 30th, 2009 at 10:03 am

Hi Paul,
It is annoying. The bug has been reported, I’ve seen numerous instances of it in the bug base, here is one:
http://bugs.adobe.com/jira/browse/FP-1283. There are a few ways to work around it, one I have used in the past:
http://blog.pixelbreaker.com/flash/swfmacmousewheel/.

As far as GAIA goes, I’ve not had the time to play, although I’ve heard great things about it, I’m sure if you ask Steven he’ll probably add it in if he thinks it’s worth while.

Gook luck.

Posted by Joe on June 11th, 2010 at 7:54 am

Hi Duncan,

Beautiful, clean and simple in graphics and in code. I can’t wait for an opportunity to implement it.

Enough of the flattering. I don’t suppose you ever developed a TextScroll.as version? Or even a MCScroll.as version!

All the best.
Joe

Posted by Asen on August 17th, 2010 at 3:17 am

Your a legend…..

Thanks

Leave a comment