ASP.NET Cafe
Tips and Tricks

Insert flash into page without "Click to activate and use this control" in IE.

Wednesday, 26 December 2007 10:43 by Dmitriy

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)

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   ASP.NET | Flash
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (5) | Comment RSSRSS comment feed

Comments

December 27. 2007 23:34

GreatWebGuy

Why wouldn't you just use the flash player detection kit provided by Adobe to embed the flash? It gets around the Click to Activate problem, it also allows you to detect the version of Flash, provide an upgrade path, and show alternative content to users that can't support an automatic upgrade. http://www.adobe.com/products/flashplayer/download/detection_kit/

GreatWebGuy

December 28. 2007 00:15

Jonathan Holland

Most Javascript based flash embedding libraries get around this just fine.

Personally, on retrofitting an old asp.net site, I simply wrote an activate flash .js file similar to yours that grabbed reference to all object and embed tags and copied the innerHTML.

Jonathan Holland

December 28. 2007 02:13

Dmitriy

[b]2 GreatWebGuy[/b]: Nice idea to use flash player detection kit provided by Adobe. My goal to make everything as simple as possible. So, I think I'll put everything from that kit inside control, to get rid of these files. :) Thanks, now I know what to add in next version! Happy new year!

Dmitriy

December 28. 2007 02:19

Dmitriy

[b]2 Jonathan Holland[/b]: Yes, I did this way too... but I think that such control can be useful, don't you. Specially, if I add flash detection features there ? I think in next year.

Dmitriy

February 7. 2008 06:46

nimesh

how to activate use of contrao without click in flash



nimesh mehra

nimesh

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Preview

January 6. 2009 16:32