how to embed a flash movie in asp.net masterpage

In this tutorial we will learn how to embed a flash movie in asp.net masterpage. To embed a flash movie in asp.net master page is not a rocket science but still most of developers found some problems while doing so. In this tutorial we will cover those two common problems that come while embedding a flash movie in asp.net master page. Let's read both case scenarios.

How to embed a flash movie in asp.net masterpage

Case Scenario 1
Let's suppose you have a masterpage and you have embeded the flash movie in it . Flash movie is located in let's suppose images folder that is placed on same level as of masterpage. In that scenario following code will be used to embed the flash movie in asp.net masterpage


<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/
shockwave/cabs/flash/swflash.cab#version=9,0,28,0"
width="925" height="300"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/
width="925" height="300">
<param name="movie" value='/images/yourflashmovie.swf' />
<param name="quality" value="high" />

<embed src='/images/yourflashmovie.swf' quality="high" pluginspage=http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash type="application/x-shockwave-flash" width="925" height="300"></embed>
</object>
Note:-
version=9,0,28,0 is the version of flash player that I am using.

Now let's suppose you have welcome.aspx page also placed on same folder of .masterpage and when you will run this welcome.aspx page, you will see flash movie on welcome.aspx page but this flash movie will not come on all other .aspx pages of your website that are located in other nested folders, the hierarchy other than .masterpage. For example you will not see flash movie in your Comments/comments.aspx webpage.

Now let's understand the reason why the flash movie is not visible in http://yourwebsite.com/Comments/comments.aspx and visible in http://yourwebsite.com/Welcome.aspx. As you have embedded the flash movie in your .masterpage, now please look at the code of object tag that will embed the flash movie in masterpage. Look at the following line codes between the <object> </object> tags

<param name="movie" value='/images/yourflashmovie.swf' />


This line causes your flash movie not to visible in all the .aspx pages placed on nested folders or placed on hierarchy other than .masterpage. When you will run the webpages such as http://yourwebsite.com/Comments/comments.aspx the path of flash movie will become Comments/images/yourflashmovie.swf which is totally wrong as we don’t have any images folder inside the comments folder. Actually the page tries to find the images folder in the same hierarchy where Comments.aspx page exists and when it fails to find any images folder then obviously it will not show required flash movie in your aspx page.

Now let’s have a look over how to resolve this issue so that once you embed the flash movie in .masterpage then it will be visible to all other webpages no matter where they exist, but inheriting that masterpage. Here’s the code that will solve your problem
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=http://download.macromedia.com/pub/shockwave/
cabs/flash/swflash.cab#version=9,0,28,0 width="925" height="300">
<param name="movie" value='<%= ResolveUrl("~/images/yourflashmovie.swf") %>' />

<param name="quality" value="high" />
<embed src='<%= ResolveUrl("~/images/yourflashmovie.swf") %>' quality="high" pluginspage=http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash type="application/x-shockwave-flash" width="925" height="300">
</embed>
</object>
ResolveUrl() plays the vital role to solve your problem.

Syntax:-
C#
public string ResolveUrl(
string relativeUrl
)

Parameters:-
relativeUrl
Type: System..::.String
The URL associated with the TemplateSourceDirectory property.

Return Value
Type: System..::.String
The converted URL.

ResolveUrl() converts a URL into one that is usable on the requesting client. If the relativeUrl parameter contains an absolute URL, the unchanged URL is returned. If the relativeUrl parameter contains a relative URL, that URL is changed to a relative URL that is correct for the current request path, so that the browser can resolve the URL. This method uses the TemplateSourceDirectory property to resolve to the absolute URL. The returned URL is for client use.

Case
Scenario 2
Once I was developing a website in which I was using css dropdown menu. Now problem was that for some reason css dropdown menu appears behind the embeded flash movie. I was very upset due to that.

Now let's have a look over how I solved that issue. Simply I add wmode attribute to the <param> inside the <object></object>. Let’s have a look over the code

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0 width="925" height="300">

<param name="movie" value='<%= ResolveUrl("~/images/yourflashmovie.swf") %>' />

<param name="quality" value="high" />

<param name="wmode" value="transparent" />

<embed src='<%= ResolveUrl("~/images/yourflashmovie.swf") %>' quality="high"
wmode="transparent" pluginspage=http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash type="application/x-shockwave-flash" width="925" height="300"></embed>
</object>

Please add the wmode attribute inside the <embed> because incase if <object> is not executed then <embed> will be executed.

wmode attribute set the background of Flash movie to transparent. It allows the background color or image of the HTML page that contains the Flash movie to show through and allows the layering of Flash content with DHTML content. For further reference please visit How to make a flash movie with a transparent background
So these are the ways to embed a flash movie in asp.net masterpage properly to get rid of various problems.


Happy Coding!!!

3 comments:

  • Anonymous
     

    Nice try but your writing style is too confusing

  • Fede
     

    Hi Adeel, it was pretty good to me and i think it will be a very helpful guide for many people... (sorry for my bad english) but can i make a question? here's my problem: i have a MASTERPAGE wich has a FLASH movie wich uses an XML file to read images from a folder "fotos", this combination works great when i use the MASTERPAGE in .aspx files within the same directory as the one of the MASTERPAGE. The problem i have is that the FLASH movie can't show the images from the folder "fotos" when i call the MASTERPAGE from .aspx files nested in other folders, IT ACTUALLY SHOWS THE FLASH MOVIE but can not show the images from the folder "fotos"...

    working example:

    wwwroot/myweb/flash.swf (flash movie)
    wwwroot/myweb/fotos (images folder)
    wwwroot/myweb/fotos_reader.xml
    wwwroot/myweb/masterpage
    wwwroot/myweb/show_flash.aspx (uses masterpage)

    NOT working example:

    wwwroot/myweb/flash.swf (flash movie)
    wwwroot/myweb/fotos (images folder)
    wwwroot/myweb/fotos_reader.xml
    wwwroot/myweb/masterpage
    wwwroot/myweb/nested_folder/show_flash_2.aspx (uses masterpage)

    (i apologize again for my bad english and if it's not clear) :( well i know this is not a forum but if you could write some tip or guide about it, it'll be very aprecieted. kind regards

  • Adeel Fakhar
     

    Hi Fade, can you please upload your code in zip format to some domain and give me the path so that i can look the issue that you are facing.