Quick Tip: iPad-Proof Your Flash Website
basix

Quick Tip: iPad-Proof Your Flash Website

Tutorial Details
  • Difficulty: Basix
  • Program: Flash
  • Estimated Completion Time: 20 mins

In this tutorial you will learn how to use SWFObject script to set up automatic redirection from a Flash website to a non-Flash backup website when it’s viewed on an iPad.


Final Result Preview

Here’s a very simple mock-up of a Flash website we’ll be using in this tutorial. If you try to access that page using iPad you won’t be able to see any content.

And here’s the final result we’ll be working toward. if you access it with iPad you’ll be able to see the animated page.


Introduction

When the wind of change blows, some people build walls, others build windmills.

– Ancient Chinese proverb

I think iPad is a great device, even though I can understand why the introduction of the Flashless tablet made quite a few people mad. I admit it did make me mad at first: just before iPad appeared in my local Apple store I finished a Flash website I considered my personal masterpiece, and I was taken aback when, trying to open it with iPad, instead of my ultra-cool Flash animation I was redirected to the backup non-Flash site I set up “just in case”. I confess it took me some time to adapt my mind to iPad, but gradually I’ve learned to believe that, like all pioneering works, it had to break out of the comfort zone, and I guess I’m cool with that.

Of course what helped me to arrive at that philosophical attitude was the number of people who hired me to set up similar redirections for their existing Flash websites. They either couldn’t afford to, or didn’t want to replace their fancy, well-designed Flash sites with simpler but more iPad-friendly ones, so the option of setting up automatic iPad redirection to a simpler, pure HTML site appealed to them.

(One may argue that, even not being able to play Flash animations, iPad is more open toward JavaScript, but unfortunately that’s not the case. The majority of JavaScript-animated sites don’t play well on iPad. Test any of these ten JavaScript animated websites on your computer and then on iPad to see what I mean.

We’ll have to wait until HTML5 is fully implemented to see the new Internet where third party plugins like Flash Player gradually lose its importance. In the meantime, the release of the iPad tablet has created a new temporary niche in web development: iPad-proofing existing Flash websites. There are thousands of excellent Flash websites out there that could benefit from such service; it’s a great work opportunity for guys like you and me.

There can be many different ways to iPad-proof a Flash website, some better than others. This tutorial offers just one possible simple solution. So let’s get down to business.


Step 1: Prepare the Backup Website

It could be a complete non-Flash website containing the HTML version of all the content copied from the Flash site, or just a single web page with only basic information and a message to the visitor, something along the lines of “you are viewing our website on a device that doesn’t allow Flash content to be displayed. To access all the features, please open our website using a computer with the latest version of the Flash player installed.”

For this tutorial, I prepared a simple JavaScript-animated web page to serve as backup. iPad is capable of playing the animation moderately well. Creating iPad-friendly JavaScript animations is beyond the scope of this tutorial, but you can find some useful information about it on the home page of the $FX() JavaScript animation library (and you are also welcome to explore the source code of the JavaScript-animated page we’ll be using as our backup).

Note: to allow the JavaScript-animated page to play when uploaded on your server you will also need to upload the fx.js file located in the Scripts folder among the downloadable files for this tutorial.


Step 2: Flash Website Source Code

We need to find out what code was used to embed the SWF file of the original Flash website into its HTML page. We can do this by opening the page in the browser and selecting the View Source option. Alternatively, we can open the page in any text editor or specialized HTML editor.

The snippet of code that embeds a SWF file in the HTML page is easy to recognize within the source code. Activate the Find function and search the page for “swf”. Doing so will reveal the name of the swf file embedded in the html page. The code surrounding the name of the swf file is the code that embeds it in the html page.

SWF files can be embedded in an HTML page in a number of different ways. Describing them all would make this tutorial endless, so if you’re curious you can just Google it. I’ll only mention some of the most popular ones.


Using HTML tags

Basic HTML tag-based code for embedding a SWF file may look like this:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="800" height="580" id="FlashWebsite" align="">
<param name=movie value="FlashWebsite.swf"> 
<param name=quality value=high> 
<param name=bgcolor value=#FFFFFF> 
<embed src="FlashWebsite.swf" quality=high bgcolor=#FFFFFF width="800" height="580" name="FlashWebsite" align="" type="application/x-shockwave-flash" pluginpage="http://www.macromedia.com/go/getflashplayer"></embed> </object> 

Chances are, that Flash site was made a while back: from the codebase attribute of the object tag we can see that the SWF is to be played by the 6th version of the Flash player.

The code is mostly self-explanatory, it’s very clear what parameter does what. One thing to mention is that as you can see, for some seemingly mysterious reason most of the parameters are indicated in the code twice. This is easy to explain: the code targets two different Internet browsers separately.

The <object> tag with all its attributes and parameters targets Internet Explorer. The <embed> tag targets the currently deprecated Netscape Navigator (that browser ignored the object tag). Hence, the repetition of the same information.

I should also mention that classid attribute of the <object> tag tells Internet Explorer that it should load the ActiveX plugin if it’s not installed; pluginpage attribute of the <embed> tag tells Netscape Navigator to display the link to the plugin page.


Using AC_RunActiveContent.js file.

AC_RunActiveContent.js is a JavaScript file that was still widely used only a few years ago. Some programmers still working with Flash CS3 Professional may still use it even now.

The code embedding the swf file using AC_RunActiveContent.js may look like this:


<script type="text/javascript" >
AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','800','height','580','align','middle','src','FlashWebsite','quality','high','bgcolor','#ffffff','name','FlashWebsite','allowscriptaccess','sameDomain','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','FlashWebsite' );
</script> 

There’s also a line of code within the tag of the page that may look like this:


<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

The purpose of the inclusion of the AC_RunActiveContent.js file was the change made by Microsoft Corporation to Internet Explorer browser in 2006. As a result of that change (brought about by certain legal matters known as “Eolas patent problem” and not directly related to technical aspects of web programming), the visitors who opened Flash websites using Internet Explorer had to click the embedded content before being able to see or interact with it.

AC_RunActiveContent.js file was a workaround that allowed users to skip that bothersome click and display the active content right away, by the means of generating the html tags within the JavaScript file. That file is typically located in the Scripts folder in the same directory as the HTML page where the swf file was embedded. Not to go into too much detail, the AC_RunActiveContent.js file is called via the AC_FL_RunContent function, and the attributes and values are passed to the file in pairs: ‘width’, ’800′, ‘height’, ’500′ and so on. You do not need to include file extensions with the names of swf files, the JavaScript file does that automatically.


Using ufo.js

UFO (an acronym that stands for Unobtrusive Flash Objects) is a JavaScript file used since 2006 for detecting versions of Flash Player and embedding swf files into HTMl pages. It was created by Bobby van der Sluis.

The code for embedding a SWF file into an HTML page with ufo.js may look like this:

<script type="text/javascript">
		var FO = { movie:"FlashWebsite.swf", width:"800", height:"580", majorversion:"8", build:"0" };
		UFO.create(FO, "container");
		</script>

The reference to the JavaScript file within the <head> tag may look like this:

<script type="text/javascript" src="Scripts/ufo.js"></script>

The arguments of the ufo.js are self-explanatory. The file was very popular, but is currently deprecated.


Using FlashReplace.js file.

FlashReplace.js is a lightweight (2.1 kb) JavaScript file created by Robert Nyman.

The code for embedding a SWF file in an HTML page using FlashReplace.js may look like this:


<script type="text/javascript">
    FlashReplace.replace("container", "FlashWebsite.swf", "Flash Website", 800, 580);
</script>

Obviously, as is the case with AC_RunActiveContent.js and ufo.js files, you will also find the reference to the JavaScript file within the <head> tag. It may look like this:


<script type="text/javascript" src="Scripts/FlashReplace.js"></script>

As you can see, FlashReplace.js is really easy. The first argument is the name of the HTML tag whose content is to be replaced with the swf file; the second argument is the name of the swf file, the third argument is the arbitrary id you can assign to the object you’re embedding, and the last two arguments are the width and height of the SWF file.


Using swfobject.js file.

swfbject.js was created by Geoff Stearns, Toby Boudreaux and Bobby van der Sluis. It is currently (2010) the most popular and widely used JavaScript library for detecting versions of Flash player and embedding swf files into HTML pages.

The code for embedding a SWF file in an HTML page using SWFObject.js may look like this:


<script type="text/javascript"><!--
			var so = new SWFObject("FlashWebsite.swf", "FlashWebsite", "800px", "580px", "9", "#FFFFFF", "high");
			so.write("container");
// --></script>

The snippet of code you just read is a very basic example of how the swfobject.js may be implemented. The code may be much more complex. For more information, check out this swfbject.js tutorial and consult the developers documentation.

The reference to the JavaScript file within the <head> tag may look like this:

<script type="text/javascript" src="swfobject.js"></script>

Step 3: Redirect to the Backup Website

If the existing Flash website is using SWFObject.js to embed swf file, you’re in luck: we are going to use SWFObject.js type of embedding to set up redirection to the non-Flash web page. If any other kind of embedding scenario is used, we’ll have to erase the old code from the HTML page and replace it with the SWFObject embedding. We are going to use SWFObject to redirect iPad visitors to the backup non-Flash website.

For the purposes of this tutorial, we are going to use a training page that has the SWF file embedded using the AC_RunActiveContent.js file. If we open the FlashWebsite.html page in a browser, we’ll see the familiar SWF file embedded in the page.

Let’s open the page called FlashWebsite.html in any text editor or any specialized HTML editor.

We should remember or write down the important information about our SWF file, such as its name (FlashWebsite.swf in our example), width (800), height (580) and background color (#FFFFFF).

Now let’s replace the line that references the AC_RunActiveContent.js file in the tag:


<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

with this line:


<script type="text/javascript" src="Scripts/swfobject.js"></script>

We have now created the reference to the SWFObject library.

Let’s locate a code that looks like this:


<script type="text/javascript" >
AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','800','height','580','align','middle','src','FlashWebsite','quality','high','bgcolor','#ffffff','name','FlashWebsite','allowscriptaccess','sameDomain','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','FlashWebsite' );
</script> 

We’ll select that bit of code and erase it. What we have now is the empty <div> tag:


<div id="container">
</div>

Below that tag, let’s paste the following:


<script type="text/javascript"><!--
			var so = new SWFObject("FlashWebsite.swf", "FlashWebsite", "800px", "580px", "9", "#FFFFFF", "high");
			so.write("container");
// --></script>

Note that the argument in parentheses for the single added parameter (so.write("container")) matches the name of the empty <div> tag: “container”. That argument tells the browser where to place the Flash content. The swf file will be embedded inside the empty <div> tag marked with the id “container”.

Note: the fifth argument in the parentheses of the SWFObject function, “9″, refers to the major version of the Flash player. When it’s of no particular importance, I prefer to give browsers some slack and to not demand the laterst version of the Flash player, so I set it here to 9, even though the current version today (2010) is 10.

Let’s save the HTML page and open it in a browser. It should look like this.

So far, nothing seems to have changed. The Flash animation played when embedded using the AC_RunActiveContent.js file, and it plays in quite the same way now, being embedded with swfobject.js file. If we tried to open that page with iPad we still wouldn’t see any content.

Let’s add two more arguments at the end of the series of arguments within the parentheses of the main function call. The first argument should be empty, just the quotation marks: “”, and the second argument should be the path to the backup non-Flash web page we want to redirect the iPad visitors to: “./JavaScriptWebsite.html”

The complete bit of code with the two new arguments added should look like this:


<script type="text/javascript"><!--
			var so = new SWFObject("FlashWebsite.swf", "FlashWebsite", "800px", "580px", "9", "#FFFFFF", "high", "", "./JavaScriptWebsite.html");
			so.write("container");
// --></script>

The first, empty argument we’ve just added is called xiRedirectUrl, and it’s used by SWFObject script to redirect users who complete the ExpressInstall upgrade. We are not using the ExpressInstall here, so we leave the argument empty. The second argument, called redirectUrl, is used by SWFObject to automatically redirect the users who do not have the required version of a Flash player installed – which is exactly the function that we needed all along. iPad tablet doesn’t have ANY version of Flash player installed, so it qualifies!

Note: “./JavaScriptWebsite.html” is the local path to the JavaScript-animated backup page we use in this tutorial. That path will allow us to test the redirection locally as well as on the server. Working with your own projects, you can set the absolute path to your backup html page instead of the local path, or a local path to any directory or subdomain where you may choose to host the backup page.


Step 4: Test the Redirection Locally

Before uploading the files to the server, we should test redirection locally. To be able to do that, we’ll simulate the iPad by setting the version attribute of the SWFObject to a non-existing version of the Flash player. Let’s go wild and set it to a 1000 (that version of the Flash player should be available sometime around 3000 A.D. if things go well at Adobe).

The code should look like this:


<script type="text/javascript"><!--
			var so = new SWFObject("FlashWebsite.swf", "FlashWebsite", "800px", "580px", "1000", "#FFFFFF", "high", "", "./JavaScriptWebsite.html");
			so.write("container");
// --></script>   

Don’t forget to save the file.

Now let’s open the FlashWebsite.html in a browser and take a look at the title bar of the web page. Instead of saying “Flash Website”, it should say “JavaScript-Animated Website”, and the last part of the URL should be JavaScriptWebsite.html instead of FlashWebsite.html. Congratulations, our redirection is working: the ultra-advanced animation you see in your viewport is done not with Flash but with JavaScript. It should look and behave like this.

Let’s reset the version value back to “9″. The code in the FlashWebsite.html should again look like this:

 

<script type="text/javascript"><!--
			var so = new SWFObject("FlashWebsite.swf", "FlashWebsite", "800px", "580px", "9", "#FFFFFF", "high", "", "./JavaScriptWebsite.html");
			so.write("container");
// --></script>

Make sure to save the file again.


Step 5: Upload Files to a Server

Using any FTP client software, let’s upload the following files to a selected directory on your server:

  • FlashWebsite.html
  • FlashWebsite.swf
  • JavaScriptWebsite.html

Upload the Scripts folder containing swfobject.js and fx.js files to the same directory on the server (to remind you, swfobject.js is the file that enables swf embedding as well as redirection, and fx.js file is the one that allows you to create and play JavaScript animation used in the backup web page which is suitable for being played on iPad).

You do not have to upload the AC_RunActiveContent.js also located in the Scripts folder to your server, even though if you’ve accidentally done so, that file would in no way interfere with the performance of all the other files you’ve uploaded.


Step 6: Test the Redirection with iPad

Here it comes, the moment of truth! Fire up your iPad tablet and access the FlashWebsite.html page uploaded to your server. Voilà! You should see the JavaScript-Animated mockup page instead of the Flash page. We’ve just iPad-proofed a Flash website.


Conclusion

You’ve just learned one of possible ways to iPad-proof an existing Flash website. There are many ways in which that goal can be achieved, and not all of them involve automatic redirection. I’d like to ask you all to share your ideas about the subject of iPad-proofing Flash website in the comments to this tutorial. Thank you for reading!

Tags: BasixTips
  • Fernando

    Great! My alternative content is basically tell them to get a fully capable device to experience the website. Although i leave that decision to the website owner XD

  • http://www.criaideias.com.br/english.hmtl Gustavo Guichard

    I can’t see the point on doing this, cause if you’ll work on an iPad (HTML) version of your site then you can spend that development time doing a better HTML site instead of 2 versions of the same.

  • Pingback: links for 2010-07-22 « My Digital Utility Belt is Bigger Than Yours

  • jay

    Accommodating Apple is like writing hacks for IE. It sucks. Which is why I find it bizarre whenever a Flash developer doesn’t Apple.

  • Priyesh

    Great advice. I do agree to a certain extent with the previous post that why spends a lot of time making a flash website then spend extra time making it compliant to the ipad. However, with apple’s increasingly popular products which do not support flash, it is important to have another plan to ensure your site is accessible to all users.

  • jay

    ^ doesn’t despise Apple

  • Henrik

    My initial reaction to this was, hey that’s kinda useful I guess.

    But spending time and money on accomodating a group of users that have clearly chosen not to view Flash sites, I’m inclined to not really look into ways of having an Ipad proof Flash website running.

    They bought the device well knowing the limitations, live with it!

  • http://www.dimitrivorontzov.com Dimitri Vorontzov
    Author

    Here’s the scenario I had in mind writing this tutorial:

    1. A very advanced existing Flash website created within the last few years;

    2. The owner of that Flash website needs his web visitors to be able to access the content, no matter what device is used to access the site;

    3. The owner of the Flash website doesn’t intent to have the existing website replaced with a new, non-Flash website.

    4. The owner of the Flash website hires a web developer to iPad-proof the existing Flash website.

    Now, you can see that paragraphs 2 and 3 of that scenario require to set up redirection. And if you get hired to do so, as in paragraph 4, this tutorial shows one of the ways to get the job done.

    I’d like to emphasize that the tutorial is not about making a new Flash site and setting up redirection to a non-Flash backup version of that site (even though I personally don’t see anything wrong with that). But the tutorial is about iPad-proofing existing lash sites their owners don’t feel like discarding just yet.

    Obviously, another possible way to iPad-proof an existing Flash site is to create a non-Flash landing page and offer the visitors the option of choosing Flash or non-Flash version. This method requires an extra click from the visitor, but it’s not necessarily a bad thing.

    Would anyone be interested in sharing their techniques of iPad-proofing Flash websites? I’m sure sharing such ideas would make this discussion valuable.

    Best,

    Dimitri Vorontzov

  • Pingback: EPAMINODAS KOMODROMOS | Cyprus flash website design

  • Pingback: Dental Clinic | Cyprus flash website design

  • http://www.thedevelopertuts.com Bratu Sebastian

    LOL, I loved Flash version 1000!

    If it reaches 1000, it will probably be called Flash One and will be embeddable into your own brain, giving you the ability to use it direcly!

    Great tutorial, and helpful, but I don’t think we’ll develop non-flash websites on Ipad, just because Steve Jobs thinks it’s hard :)

  • Andrew

    Just a fat message saying “Buy a computer” will also do. Tbh!

  • http://www.dimitrivorontzov.com Dimitri Vorontzov
    Author

    Right!

    Or I suppose you can set up redirection to redirect not to a backup site, but to a page like this:

    http://gizmodo.com/5458382/8-things-that-suck-about-the-ipad

    • http://michaeljameswilliams.com/ Michael Williams

      Haha!

  • http://www.widecircle.se Niklas

    Hi there!
    I find it much better to have alternative content underneath the flash. That’s not hard to do if using SWFObject and some php. If also SWFAddress is present you can match the subsections of the alternative site with the deeplinks within flash. I do this all the time with my flashsites. That way they are also SEO-friendly. I can’t really see the need for redirection here. If using alternative content & the user has flash installed they see the flashsite & if they don’t have flash installled – well then they see the alternative site no matter the device.

    Niklas

    • http://www.dimitrivorontzov.com Dimitri Vorontzov
      Author

      Niklas, I would be personally grateful, and I think a lot of readers would benefit from your knowledge, if you could expand on what you wrote in your comment and give some details on how exactly you do that. May I ask you to write another, longer, more detailed comment on the topic?

      Best,

      Dimitri Vorontzov

    • http://www.widecircle.se Niklas

      Hi Dimitri!

      This is kind of a big topic to answer here in this area.
      I would suggest to start with reading the articel below over at Adobe.
      http://www.adobe.com/devnet/flashplayer/articles/alternative_content.html
      I’m thinking of maybe send in a tutorial here on active tuts regarding these things.
      I read frequently how people are iPAD proofing there websites – especially flash.
      But I don’t see it that way. It’s much better to have alternative content – that way not only iPADs a supported once flash is not present on a device. I’m kind of surprised because alternative content has been around for yrs.

      Niklas

      • http://www.dimitrivorontzov.com/ Dimitri Vorontzov
        Author

        Thank you Niklas, i can’t talk for the active.tutsplus.com editors, but I personally think your tutorial on alternative content would be useful and welcome.

  • http://www.almogdesign.net Almog Koren

    This is an outdated tutorial, your using SWFObject v1.5 which works different from SWFObject v2.2.

    What I don’t understand this tutorial was published on Jul 22nd 2010 and SWFObject 2.2 came out Jun 13, 2009. Did you knowingly use outdated files?

  • http://www.dimitrivorontzov.com Dimitri Vorontzov
    Author

    Good point, Almog. Could you please share your experience of using SWFObject v2.2 for iPad-proofing Flash websites?

  • http://www.dimitrivorontzov.com/ Dimitri Vorontzov
    Author

    I was hoping Almog would find time to share his experience with setting up redirection using SWFObject v2.2, but Almog is most likely too busy. So here’s my version of setting up automatic redirection using the 2.2 version.

    Add this chunk of code to your page, if you’re using the 2.2 version of SWFObject, and you’ll achieve the same result as was outlined in the main body of the tutorial.

    swfobject.addLoadEvent(function() {
    if (!swfobject.hasFlashPlayerVersion(“9.0.18″)) {
    window.location = “http://www.inserttheurlofthebackupsitehere.com”;
    }
    });

  • http://www.entendiste.com.ar Jose

    Hi, thanks for this tips and example.
    But its working with the iphone?
    Thanks.Regards.

  • Perry S

    Hello,
    My website is alpmusic.com

    We have flv video files throughout the site embedded via JWPlayer. Is it possible to still have this with an iPad or even for flv files we have to convert the site? Is there even a way to view FLV files embedded in a website on iPads?

    Thank you!
    Perry S.