Most SWF containers I've stumbled upon were complex, would cost me a lot, or simply didn't have the functionality I required. This small Web Control is a container for any SWF control, and also dynamically receives Flash variables.
Using the code
To use this code, simply add the class
EmbeddedObject to your web app, don't forget to change the name of the namespace to suit your requirements. Once added, compile the application so that the toolbox items will refresh, and drag the embedded SWF object to the web page of your selection.
To dynamically add Flash variables at runtime, use the
The new Flash variables will be rendered into the control and sent to the client.
The simplicity of the code is reflected in the rendering method, which creates a simple Flash object with the embedded Flash variables. If you look at the source code of any web page that contains Flash commercials, you will probably see something similar.
protected override void RenderContents(HtmlTextWriter writer)
StringBuilder sb = new StringBuilder();
string flashVariableString = "";
foreach (FlashVariable fv in FlashVariables)
flashVariableString += fv.Name + "=" + fv.Value + "&";
if (FlashVariables.Count > 0)
flashVariableString = flashVariableString.Substring(0,
flashVariableString.Length - 1);
sb.Append("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
sb.Append("codebase=\"http: "shockwave/cabs/flash/swflash.cab#version=5,0,2,0\" ID=Moshe Width=" +
Width.Value.ToString() + " Height=" + Height.Value.ToString() + " > ");
sb.Append("<param name=movie value=\"" + FilePath.ToString() + "\"> ");
sb.Append("<param name=FlashVars value=\"" + flashVariableString + "\">");
sb.Append("<param name=quality value=high> ");
sb.Append("<param name=BGCOLOR value=#FFFFFF>");
sb.Append("<embed src=\"" + FilePath.ToString() + "\" ");
sb.Append("pluginspage=\"http: "index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application" +
sb.Append("Width = " + Width.Value.ToString() + " ");
sb.Append("Height = " + Height.Value.ToString() + " ");
sb.Append("FlashVars=\""+ flashVariableString + "\" ");
writer.Write("Custom Flash Control");
Points of Interest
This little piggy saved me a lot of trouble when trying to use other purchased SWF wrapper controls. But sometimes, it's best searching for extended functionality.
If you are a web designer that works a lot with Flash, you will find this very helpful since you can communicate between your C# code in the web server and your Flash controls easily.