All web developers and designers should know by now that you should not use the traditional <object><embed>... method for placing Flash content on your site. Macromedia (Adobe) recommends using javascript to load the Flash content and it works just fine. However, if you are a .NET programmer and have a lot of flash content it is fairly easy to create a Control that handles the repetitive tasks.

First we need to create a little javascript file. I place my javascript in a /Utility/ directory (a la CommunityServer) and here it is:


function loadFlashDoc(fPath, fWidth, fHeight){
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=",0,29,0" ');
document.write(' width="' + fWidth + '" height="' + fHeight + '"> ');
document.write(' <param name="movie" value="' + fPath + '"> ');
document.write(' <param name="quality" value="high"> ');
document.write(' <param name="wmode" value="transparent" /> ');
document.write(' <embed wmode="transparent" quality="high" pluginspage="" type="application/x-shockwave-flash" ');
document.write(' src="' + fPath + '" ');
document.write(' width="' + fWidth + '" ');
document.write(' height="' + fHeight + '"></embed> ');


Nothing to complex here. Just write out the object & embed lines used to show the flash file specified as fPath with the fWidth and fHeight.

Now for the ASP.NET Control.

public class FlashLoader : System.Web.UI.Control

        #region FlashFile property
        private String _FlashFile;
        public String FlashFile
            get { return _FlashFile; }// get
            set { _FlashFile = value; }// set
        }// property


        #region Width property
        private int _Width;

        public int Width
            get { return _Width; }// get
            set { _Width = value; }// set
        }// property


        #region Height property
        private int _Height;

        public int Height
            get { return _Height; }// get
            set { _Height = value; }// set
        }// property


        #region Title property
        private String _Title = String.Empty;
        /// <summary>
        /// A Title for the Flash File
        /// </summary>
        public String Title
            get { return _Title; }// get
            set { _Title = value; }// set
        }// property


        protected override void OnLoad(EventArgs e)
            if (String.IsNullOrEmpty(FlashFile))

            if (!Page.ClientScript.IsClientScriptIncludeRegistered(typeof(FlashLoader), "flashLoader"))
                Page.ClientScript.RegisterClientScriptInclude(typeof(FlashLoader), "flashLoader", "/Utility/loadFlash.js");

        protected override void Render(HtmlTextWriter writer)
            if (String.IsNullOrEmpty(FlashFile))

            writer.WriteLine(String.Format(@"<script type=""text/javascript"">loadFlashDoc('{0}', '{1}', '{2}');</script>", FlashFile, Width, Height));
            writer.Write("\t<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\",0,0,0\"");
            writer.WriteLine(String.Format(@"width=""{0}"" height=""{1}"" id=""zoom_map"" align=""top"">", Width, Height));
            writer.WriteLine(String.Format(@"<param name=""movie"" value=""{0}"" />", FlashFile));
            writer.WriteLine("\t\t<param name=\"wmode\" value=\"transparent\" />");
            writer.WriteLine("\t\t<param name=\"quality\" value=\"high\" />");
            writer.WriteLine("\t\t<param name=\"bgcolor\" value=\"#FFFFFF\" />");
            writer.WriteLine(String.Format(@"<embed src=""{0}"" quality=""high"" bgcolor=""#FFFFFF"" width=""{1}"" height=""{2}"" name=""{3}"" align=""top"" wmode=""transparent"" type=""application/x-shockwave-flash"" pluginspage=""""></embed>", FlashFile, Width, Height, Title));



To use this control you would just register your control and add the tag as such:


<FLASH:FlashLoader id="Flash" runat="server" FlashFile="/path/to/file.swf" Width="475" Height="275" Title="Flash File" /> 

And you will get output as follows:

<script src="/Utility/loadFlash.js" type="text/javascript"></script>
<script type="text/javascript">loadFlashDoc('/path/to/file.swf', '475', '275');</script>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=",0,0,0"width="475" height="275" id="zoom_map" align="top">
<param name="movie" value="/path/to/file.swf" />
<param name="wmode" value="transparent" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="/path/to/file.swf" quality="high" bgcolor="#FFFFFF" width="475" height="275" name="Flash File" align="top" wmode="transparent" type="application/x-shockwave-flash" pluginspage=""></embed>


Comments are closed