Click here to Skip to main content
13,353,462 members (65,737 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 1 Sep 2008

Simple ASP.NET SWF container control with Flash variables

, 1 Sep 2008
Rate this:
Please Sign up or sign in to vote.
Easy to use ASP.NET SWF container control with Flash variables.


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 AddVariable method.

The new Flash variables will be rendered into the control and sent to the client.

EmbeddedObject1.AddVariable("FLV_PATH", txtFlvPath.Text)

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(&quot;<object classid=\&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\&quot; &quot;);
         sb.Append(&quot;codebase=\&quot;; + 
                   &quot;shockwave/cabs/flash/,0,2,0\&quot; ID=Moshe Width=&quot; + 
                   Width.Value.ToString() + &quot; Height=&quot; + Height.Value.ToString() + &quot; > &quot;);
         sb.Append(&quot;<param name=movie value=\&quot;&quot; + FilePath.ToString() + &quot;\&quot;> &quot;);
         sb.Append(&quot;<param name=FlashVars value=\&quot;&quot; + flashVariableString + &quot;\&quot;>&quot;);
         sb.Append(&quot;<param name=quality value=high> &quot;);
         sb.Append(&quot;<param name=BGCOLOR value=#FFFFFF>&quot;);
         sb.Append(&quot;<embed src=\&quot;&quot; + FilePath.ToString() + &quot;\&quot; &quot;);
         sb.Append(&quot;pluginspage=\&quot;; + 
                   &quot;index.cgi?P1_Prod_Version=ShockwaveFlash\&quot; type=\&quot;application&quot; + 
                   &quot;/x-shockwave-flash\&quot; &quot;);
         sb.Append(&quot;Width = &quot; + Width.Value.ToString() + &quot; &quot;);
         sb.Append(&quot;Height = &quot; + Height.Value.ToString() + &quot; &quot;);
         sb.Append(&quot;bgcolor=#FFFFFF &quot;);
         sb.Append(&quot;FlashVars=\&quot;&quot;+ flashVariableString + &quot;\&quot; &quot;);
         sb.Append(&quot;TYPE=\&quot;application/x-shockwave-flash\&quot; &quot;);
     catch(Exception ex)
         writer.Write(&quot;Custom Flash Control&quot;);

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Team Leader DBSophic
Israel Israel
I started my IT life in the military where I served as an oracle DBA and a computer programmer for several years.
After that I spent 3 years I've been a consultant for Java and oracle technologies.
Now adays I'm running a software development team in a .net winforms environment.
I also do some freelancing here and there.

You may also be interested in...


Comments and Discussions

Generalou, I'm gonna check this one out :D Pin
Seishin#1-Sep-08 10:48
memberSeishin#1-Sep-08 10:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 1 Sep 2008
Article Copyright 2008 by maorray
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid