In some recent versions of Internet Explorer, Flash movies need a click to activate them. It is frustrating, especially if your Flash is part of the page design. But, some solutions are available to fix this issue. In other words, we need some code for IE and a different one for Opera, Firefox, Safari, and other favorite browsers. An ASP.NET custom control can make this possible.
Using the code
Just add this control to your toolbar, and that's all. Drag and drop on the page, select an SWF file to embed.
Points of interest
Let's consider details. First of all, we need to know the browser. No problems:
Page.Request.Browser.Browser will return the browser name. So, now, we know what browser requested our page. The next step is to render the correct HTML for the browser. The main idea is to write a Flash
document.getElementById(id).innerHTML = content;
To embed it inside our assembly, we need to change the build action to "Embedded Resource" and add this line to AssemblyInfo.cs:
Also, we need to provide the following properties:
Transparent), and the Flash file URL (
SWFURL). But this is simple stuff.
Another interesting thing, we might want to browse for the SWF file in design mode. To do this, we need to add the following attribute to our
It tells the designer to use the
UrlEditor class as
UITypeEditor for this property.
More information can be found inside the source code.
This article was originally posted on ASP.NET Cafe: Tips and Tricks, and then with a few changes posted on CodeProject. Flash Embedding was tested in IE 6 and 7, FireFox, Opera, and Safari.
- January 5th... I found a big ugly bug here, and I corrected it.