Posts tagged flash
embedding flash in server control
Jun 29th
Problem:
When you got your website (aspx website), especially when you already put url rewriting, you want to embed flash ( doesnt matter if its swf or flv)
You need to have relative path, starting with ("~/" ) in the url.
Solution:
you can put the code in your server control, so it will be easier to integrate
FlashPlayer.ascx
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="745" height="181" id="header" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value='<asp:Literal ID="Literal1" runat="server"></asp:Literal>' /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />
<embed src='<asp:Literal ID="Literal2" runat="server"></asp:Literal>' quality="high" bgcolor="#ffffff" width="745" height="181" name="header" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_nl" />
</object>
and in the FlashPlayer.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = Page.ResolveUrl("~/yourpath");
Literal2.Text = Page.ResolveUrl("~/yourpath");
}
and you will got flash playing! enjoy ^_^
================================
thank to Marc Neeft, hereby his input :
it would be even more powerful when you add the movieUrl, width and height as properties of the usercontrol:
private string movieUrl = String.empty;
private int movieWidth = 0;
private int movieHeight = 0;
protected void Page_Load(object sender, EventArgs e)
{
// todo: check if url, width and height are set, if not, throw exception
Literal1.Text = Page.ResolveUrl(movieUrl);
Literal2.Text = Page.ResolveUrl(movieUrl);
Literal3.Text = movieWidth;
Literal4.Text = movieHeight;
}
public string MovieUrl
{
get { return movieUrl; }
set { movieUrl = value; }
}
public string MovieWidth
{
get { return movieWidth; }
set { movieWidth = value; }
}
public int MovieHeight
{
get { return movieHeight; }
set { movieHeight = value; }
}
Of course you need to add the 2 extra literals and the errorchecking yourself but you get the general idea.
<uc:FlashPlayer id="Flashplayer" runat="server" MovieUrl="~/flash
/movie.flv
" MovieWidth="300" MovieHeight="150" />