Subject: dinamically showing a .swf file in a popup window
Posted By: ACE2084 Post Date: 4/26/2005 2:43:12 PM
hi, i like to show a .swf file in a popup window that receives on the querystring a variable indicating what .swf to show. i have this inside the body tag of the popup window:
<OBJECT codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"
                height="114" width="250" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>
                <PARAM NAME="_cx" VALUE="6615">
                <PARAM NAME="_cy" VALUE="3016">
                <PARAM NAME="FlashVars" VALUE="">
                <PARAM NAME="Movie" VALUE="XX.swf">
                <PARAM NAME="Src" VALUE="XX.swf">
                <PARAM NAME="WMode" VALUE="Window">
                <PARAM NAME="Play" VALUE="-1">
                <PARAM NAME="Loop" VALUE="-1">
                <PARAM NAME="Quality" VALUE="High">
                <PARAM NAME="SAlign" VALUE="">
                <PARAM NAME="Menu" VALUE="-1">
                <PARAM NAME="Base" VALUE="">
                <PARAM NAME="AllowScriptAccess" VALUE="always">
                <PARAM NAME="Scale" VALUE="ShowAll">
                <PARAM NAME="DeviceFont" VALUE="0">
                <PARAM NAME="EmbedMovie" VALUE="0">
                <PARAM NAME="BGColor" VALUE="">
                <PARAM NAME="SWRemote" VALUE="">
                <PARAM NAME="MovieData" VALUE="">
                <PARAM NAME="SeamlessTabbing" VALUE="1">
                <embed src="XX.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
                    type="application/x-shockwave-flash" width="250" height="114"> </embed>
            </OBJECT>

What i want to do is to change on the page load the value of the atributes that represent the path of the .swf (the code is in c#)
 i have this on the page load:

int idUnit= Convert.ToInt32(Request.QueryString["id"]);
string strflashpath= Server.MapPath("\\Upload\\")+idUnit+".swf";

"strflashpath" is the path of the .swf i want to show on the popup.

any suggestions? thanks in advance...
Reply By: planoie Reply Date: 4/26/2005 4:26:27 PM
- Wrap all of the <OBJECT> HTML inside of an asp:literal control.
- Place some kind of token where you want to drop the file name
(Right now you have 'XX.swf' so that could work fine.  I like to use something like '%%SWFFILE%%'.)
- In the ASPX codebehind, do this:
   litMyLiteral.Text = litMyLiteral.Text.Replace("XX.swf", strFlashPath)
      or
   litMyLiteral.Text = litMyLiteral.Text.Replace("%%SWFFILE%%", strFlashPath)

You do NOT want to use Server.MapPath because that will return the absolute LOCAL path (i.e. "C:\inetpub\wwwroot\myapplication\myswfs\myswf.swf") to the browser which will be of no use.  Instead, use Page.ResolveUrl("~/myswfs/myswf.swf") which will return the root relative HTTP path to the swf file ("/myapplication/myswfs/myswf.swf").

-Peter
Reply By: ACE2084 Reply Date: 4/27/2005 9:18:35 AM
Thanks, i wraped the object tag like this:
<asp:Literal ID=litMyLiteral Runat=server>
<OBJECT.....
   ....  
   <PARAM NAME="Movie" VALUE="%%SWFFILE%%">
   <PARAM NAME="Src" VALUE="%%SWFFILE%%">
   ....
<embed src="%%SWFFILE%%" ...></embed>
</OBJECT>
</asp:Literal>

and i have this in codebehind:

int idUnit= Convert.ToInt32(Request.QueryString["id"]);
            string strFlashPath= Page.ResolveUrl("\\Upload\\"+idUnit.ToString()+".swf");
            litMyLiteral.Text = litMyLiteral.Text.Replace("%%SWFFILE%%", strFlashPath);

the problem is that when i request the page, it never goes to codebehind and the html source remains with the token.
the page is called like this:

hlAFP.NavigateUrl="javascript:var w=window.open('PopUpFAd.aspx?id=0','', 'width=250,height=250,scrollbars=no,resizeable=no');";

i mean, i assign this to a hyperlink control in codebehind in another page, and the link works well, but the page PopUpFAd.aspx never gets into its codebehind...
Page Load
Reply By: planoie Reply Date: 4/27/2005 9:46:41 AM
Where in the codebehind do you have that code?


You probably also want to change this line:

string strFlashPath= Page.ResolveUrl("\\Upload\\"+idUnit.ToString()+".swf");

to this:

string strFlashPath= Page.ResolveUrl("~/Upload/"+idUnit.ToString()+".swf");

The \ is used for local file references while the / is for web resources (though I don't think it will matter much.  The key is using the ~ if you use the /.  If you preceed any url with / it tells the browser to look at the web site root.  Assuming that you probably are running this application in a virtual directory, the browser will be referencing a bad resource.  By adding the ~ you'll get the complete root relative URL for the resource.

-Peter
Reply By: planoie Reply Date: 4/27/2005 9:48:16 AM
I meant to include:

You do not have to use "~/" in the url.  You can use just "upload/..." but then you need to make sure this relative reference is correct to the context of the page that is requesting it.

-Peter
Reply By: ACE2084 Reply Date: 4/27/2005 9:53:07 AM
hi again. now i solved the postback problem. for some reason i do not had this on private void InitializeComponent():
 this.Load += new System.EventHandler(this.Page_Load);

so my logic will never goes into page load eventhandler.
now the token is replaced with the right one, but the .swf doesn't appear on the page. i think it could be something about the size of the .swf and the size of the window in which i like the .swf be shown. ??????

Reply By: ACE2084 Reply Date: 4/27/2005 10:07:54 AM
thanks.., at last the .swf are showing!!!. now, i want to resize it client side. some kind of this i asked in a topic i posted before and you reply telling that with some scripting i can accomplish this
Reply By: planoie Reply Date: 4/27/2005 10:59:00 AM
Yes, like I mentioned before, I don't have any idea if you can read the swf and get the size of it.  Presumably, there are flash APIs or something that could read the proprietary SWF format and give you this information.  Otherwise, there may be numerous ways you could accomplish this task with some client scripting.  Try a javascript and/or DHTML forum for the specifics on doing this.

-Peter

Go to topic 29765

Return to index page 567
Return to index page 566
Return to index page 565
Return to index page 564
Return to index page 563
Return to index page 562
Return to index page 561
Return to index page 560
Return to index page 559
Return to index page 558