Location > Server Controls > SWFObject.Net

SWFObject.Net C# Wrapper Server Control

SWFObject.NET is a C# ASP.NET server control that wraps the functionality of the SWFObject 2.2 JavaScript library. In the past a number of methods have been developed for embedding flash onto your web page. SWFObject works great to avoid the ‘click to activate’ problems that affect IE6, IE7 and Opera 9+. The browser displays an outline around the flash object and a tooltip ‘click to activate’.

Microsoft has now licensed the technologies from Eolas, removing  the ‘click to activate’ requirement in Internet Explorer. There are still plenty of good reasons to load your flash using SWFObject or a similar method.

SWFObect.Net Key Properties and Features:

  • ScriptLocation - specifies the location of the SWFObject JavaScript file either Embedded or GoogleAPI.
  • ScriptVersion - specifies the SWFObject script version that is used by the control, currently it is version 2.2.
  • FlashUrl - specifies SWF file's URL it can be a absolute, virtual or relative URL.
  • AlternateContent - specifies the HTML content output underneath the flash, this needs to be smaller than the size of your flash or it may be visible. If the flash cannot be displayed the content will be seen.
  • RequiredFlashVersion - specifies the required flash version and is passed onto the SWFObject as an argument.
  • Width - specifies the width of the control and the flash.
  • Height - specifies the width of the control and the flash.
  • Quality - specifies the quality you wish your flash movie to play at. If no quality is specified, the default is High.
  • WMode - specifies the flash wmode and allows you to set the flash to be transparent.
  • Play - plays the flash when the page loads.
  • Menu - specifies if the flash context menu is displayed.
  • Loop - specifies if the flash movie loops after it has finished playing.
  • ShowGetFlashPlayer - adds the 'get flash player' image and link to download the flash player from Adobe to the AlternateContent.
  • UseExpressInstall -  specifies if express install is used.
  • FlashParams - gives access to specify parameters other than what can be set using the properties above.
  • FlashAttributes - gives access to specify attributes other than what can be set using the properties above.
  • FlashVariables - allows you to specify custom flash variables.

SWFObject.Net is released under the MIT License http://www.opensource.org/licenses/mit-license.php

Issues / Updates

  • 17 Nov 2009 - Fixed bug with the embedded 'Get Flash Image' URL
  • 19 Aug 2009 - Added support for using Google AJAX Libraries API via the ScriptLocation property.
  • 17 Aug 2009 - Updated to embedded library to SWFObject 2.2.
  • 12 Jan 2009 - SWFObject.Net currently does not support being loaded from inside an AJAX Panel. This is due to the way SWFObject 2.1 JavaScript library loads.
  • 9 April 2009 - Added support when website does not run under Full Trust.
  • 13 May 2009 - Added User Control example.

Tips

  • If you are using a percentage width or height for your flash ensure your parent tags html, body and form have their width and height set.

SWFObject.Net Example User Control

Menu
Loop
Play
Background
 
The Flash 6 plugin or higher is required to view content on this page, but was not detected on your browser.
Get Flash Player

SWFObject.Net Example Code

<%@  Control Language="C#" %> 
<%@ Register Assembly="SWFObject.Net" Namespace="Juna.Web.UI" TagPrefix="juna" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<script language="C#" runat="server"
 
    public override void DataBind() 
    { 
 
    } 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack) 
        { 
            Background.GetWeb216Colors(); 
            Play.Checked = SWFObject1.Play; 
            Menu.Checked = SWFObject1.Menu; 
            Loop.Checked = SWFObject1.Loop; 
            Background.SelectedColor = SWFObject1.BackColor; 
        } 
    } 
 
    protected void Apply_Click(object sender, EventArgs e) 
    { 
        SWFObject1.Play = Play.Checked; 
        SWFObject1.Menu = Menu.Checked; 
        SWFObject1.Loop = Loop.Checked; 
        if (!Background.SelectedColor.IsEmpty) 
        { 
            SWFObject1.BackColor = Background.SelectedColor; 
            SWFObject1.WMode = FlashWMode.Transparent; 
        } 
    } 
 
</script> 
 
<table> 
    <tr> 
        <td> 
            <div class="InfoPanel" style="width: 210px"
                <table border="0" cellpadding="0" cellspacing="0" class="Pad" width="300"
                    <tr> 
                        <td style="width: 100px"
                            <asp:label id="LabelMenu" runat="server" cssclass="SubHead" text="Menu"></asp:label> 
                        </td> 
                        <td> 
                            <asp:checkbox id="Menu" runat="server" text="" cssclass="SubHead" /> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td style="width: 100px"
                            <asp:label id="LabelLoop" runat="server" cssclass="SubHead" text="Loop"></asp:label> 
                        </td> 
                        <td> 
                            <asp:checkbox id="Loop" runat="server" text="" cssclass="SubHead" /> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td style="width: 100px"
                            <asp:label id="LabelPlay" runat="server" cssclass="SubHead" text="Play"></asp:label> 
                        </td> 
                        <td> 
                            <asp:checkbox id="Play" runat="server" text="" cssclass="SubHead" /> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td style="width: 100px"
                            <asp:label id="LabelBackground" runat="server" cssclass="SubHead" text="Background"></asp:label> 
                        </td> 
                        <td> 
                            <telerik:RadColorPicker ID="Background" runat="server" ShowIcon="True"></telerik:RadColorPicker> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td style="width: 100px"
                            &nbsp; 
                        </td> 
                        <td> 
                            <asp:button id="Apply" runat="server" cssclass="Button" onclick="Apply_Click" text="Apply Settings" /> 
                        </td> 
                    </tr> 
                </table> 
            </div> 
        </td> 
        <td style="padding-left: 20px"
            <juna:SWFObject ID="SWFObject1" runat="server" Height="100px" Width="200px" FlashUrl="~/your_flash.swf"
                <alternatecontent> </alternatecontent
            </juna:SWFObject> 
        </td> 
    </tr> 
</table>