In some recent versions of Internet Explorer flash movies need a click to activate them. It is frustrating specially if your flash is a part of page design. But some solution known. In other words we need one code for IE and other for Opera, Firefox, Safari and other your favorite browsers. But asp.net custom control makes this possible.
Consider details. First of all we need to know the browser. No problems - Page.Request.Browser.Browser returns browser name. So, now we know what browser request our page. Next step, is to render correct html for IE. The main idea - to write flash <object> node from external javascript file inside some container (div in this implementation). Ok. But it's not very good to carry JavaScript file with our custom control. Yes, but we are going to embed javascript inside our dll. Here is our javascript:
function ActivateFlash(id,content)
{
document.getElementById(id).innerHTML = content;
}
Fairly simple stuff... But we can't write it on the same page, it's important to put it in the external javascript resource. So, it's the file activate.js.
To embed it inside our assembly we need to change build action to "Embedded Resource" and add this line to AssemblyInfo.cs:
[assembly: System.Web.UI.WebResource("EmbedFlash.activate.js", "application/x-javascript")]
Also, we need to provide following properties: Width, Height, WMode (windowed, opaque, transparent) and flash file url (SWFURL).
Another interesting thing, we want to browse for the swf file in design mode. To do this we need to add following attribute to our SWFURL property:
[EditorAttribute(typeof(System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
It tells designer to use UrlEditor class as UITypeEditor for this property.
More information you can find inside source code.
Embed Flash - Sources.zip (96.10 kb)