There seems to be a lot of confusion about the code needed to properly embed Flash objects within a website: it’s the most frequently asked question at this site’s forum. The rise of social networking sites like Myspace (who filter lots of codes) and the Eolas patent enforcement have thrown quite some confusion into the mix. In this tutorial, I’ll shortly align the best options to embed Flash.

Single embed code

Let’s start with the easiest way to embed Flash in a website, with a single embed code. We presume we have a mediaplayer.swf file located in the same directory as the HTML page it’s embedded in

Of these parameters, the most important one is the src. This contains the location of the SWF file to include, here mediaplayer.swf. If the SWF file resides in another directory, we can point to it with a relative path (eg. ../flash/mediaplayer.swf or an absolute path (eg. http://www.myserver.com/flash/mediaplayer.swf).

The width and height parameters comply with the width and height of the SWF in pixels, but they can also be entered as a percentage of the SWF container (eg: width=”100%”).

Last, the allowscriptaccess and allowfullscreen parameters tell the browser the SWF can both communicate with external scripts (and link to external pages) and use the new fullscreen mode. If you do not want to allow this, you can remove both parameters, since they default to respectively sameDomain and false.

Extra Parameters

The code listed above uses only a couple of the available parameters. A complete list of them can be found at Adobe’s website, but let’s show the most interesting ones here:

bgcolor (#rrggbb): set the SWF background color using a hexadecimal value.

flashvars (variables): the variables placed here will be loaded in the SWF.

menu (true, false): set this to false to hide most of the rightclick menu.

wmode (opaque, transparent, window): set this to either transparent or opaque to fix z-index or flickering issues.

Flashvars

Of the above parameters, the most interesting one is flashvars, which allows you to send startup variables to the SWF. This site’s FLV Media Player and Image Rotator support a large number of these variables, making them easy to customize and reuse. Let’s give our example mediaplayer.swf three flashvars; one for the list to play, one for the background color and one for automatically starting the song:

As you can see, flashvars are entered as a single string, with an = symbol separating the name and value and an “&” symbol separating subsequent flashvars. There’s no limit to the number of flashvars you can add to the embed code. Once more note that the FLV Media Player and Image Rotator also support quite a few of them.

Flashvars problems

Three problems related to flashvars often cause them not to load. The first relates to relative linking of files. When linking to MP3, image and XML files, you should always start from the location of the HTML in which the SWF is embedded. So, in the previous example, if the SWF was to be put in a subdirectory, the flashvar pointing to the playlist would remain to be file=playlist.xml and not file=../playlist.xml! There’s an exception: the path of FLV files should be given relatively from the SWF file. In order to prevent confusion, you can always point to files using an absolute URL (including the http://www part).

The second problem relates to the importing of XML files. Due to security restrictions, Flash can only import XML files if they reside on the same domain as the SWF file. So, in our mediaplayer example, if the SWF is located in the domain http://www.myserver.com the playlist.xml should also reside on http://www.myserver.com. A workaround for this is to use a simple crossdomain.xml file, which should be installed in the root of the site that contains the XML. Here’s the one from YouTube.

The third problem relates to the three symbols ?, = and &. Since they are used to stack the flashvars, they cannot be used in the flashvars themselves. By escaping these vars, the problem can be solved. Therefore, replace the three symbols with their escaped strings and unescape() them again in the SWF:

? → %3F

= → %3D

& → %26

Eolas, XHTML & javascript

In 2005, a large embed problem arised after a small company named Eolas filed (and won) a lawsuit against Microsoft. Eolas enforced a patent on automatically embedding external applications (like Flash) in webpages. As a result, Microsoft updated Internet Explorer: you’ll see a grey border appearing around an SWF when you move your mouse over it. Before interacting with it, you first have to click once to activate it. Very annoying.

The SWFObject instance will create the code needed to embed the mp3player.swf. It sets it’s dimensions to 300 by 250 pixels and also sends the flashvars for the file, backcolor and autostart variables (with a nice, separate line per flashvar). Finally, the instance replaces the text by the SWF, so we can see a Flash movie directly embedded in our page, without borders and with XHTML validity!

Wrapping Up

The implementation of SWFObject wraps up this general overview of the embedding of Flash in websites. For questions or hints, or in case I’ve forgotten anything, please join this site’s forum. If you want to create specific embed codes for the FLV Media Player or the Image Rotator, take a look at the setup wizard, which can automatically generate it.

The Web.Developer Server Suite™ is a Windows-based Platform for the development, testing and deployment of websites and web applications.

» Now integrated with ASP.NET and Java!

“Maximize your productivity with the industry leading web deployment Platform for PHP and MySQL. Reduce the time and effort involved in manually integrating, configuring, and setting up Server components and websites.”

Download: SQL Anywhere Developer EditionSponsored by Sybase
SQL Anywhere provides data management and exchange technologies designed for database-powered applications that operate in frontline environments without onsite IT support. SQL Anywhere is offered at no cost for development and testing. Register before the 60 day evaluation expires to continue using the product free of charge for development and testing, without a time limit. Click here to download.

Kernel Excel File Recovery Software- recovers corrupted excel files files corrupted due to unexpected system shutdown, virus attacks. During repairing process a complete scan of the all the damaged documents is performed to locate and extract the recoverable information. After the complete scanning the files which are recoverable are recovered and copied in the user defined location. Kernel for Excel File Repair Software uses quick algorithm for searching and repairing corruptions in the corrupted files and hence is a fast, simple and easy to use excel file recovery software, which helps you to recover and repair your corrupt damaged excel files in minutes. Kernel for Excel – corrupted file recovery software supported versions includes Excel 2003, Excel XP, Excel 2000, Excel 97, Excel 95 files.

Featured Posts

Career Opportunity (source : http://www.starperforma.com ) PT. Star Performa is founded in 2003 with our aim to help our clients in the highest business performance. Using our expertise in management and technology consulting, we deliver business consulting, business process design, system integration, and application design and management. In our rapid growth, we are seeking talented […]