Raheel Khan
Raheel Khan

Reputation: 51

Dynamic SWF File in a Html/Javascript page

I need to change the swf embedded n my html page, when I click on a menuItem in the same page. I do not want to navigate to a new page with another swf because that will be a bit slower. So, I need some solutions. currently I am using div in the html to include a swf file in it. my current code is given below , the javascript method showAlert will be changed later , but this is the one I want to change the SWF file right now...

   <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
      <title>Wrapper Being Called</title>
       <script type="text/javascript" src="/TestProject/flashfiles/swfobject.js">       </script>
       <script type="text/javascript">
          var swfVersionStr = "0";
          var xiSwfUrlStr = "";
          var flashvars = {};
        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "always";
        var attributes = {};
        attributes.id = "WrapperCaller";
        attributes.name = "WrapperCaller";
        attributes.align = "middle";
        swfobject.embedSWF(
            "/TestProject/flashfiles/Project1.swf", "flashContent",
            "100%", "100%",
            swfVersionStr, xiSwfUrlStr,
            flashvars, params, attributes);
    </script>
</head>

 <SCRIPT LANGUAGE="JavaScript">
     function showAlert(a) {
        alert(a);
        return "successful";
     }

 </SCRIPT>

<body>
    <div id="flashContent"/>

Upvotes: 1

Views: 823

Answers (1)

Raheel Khan
Raheel Khan

Reputation: 51

Ok, I got the solution here, it's pretty simple and the speed is faster than putting the flash file in a separate page and navigating to it. All the swf files are on the server.

<body>
<table align="center" cellpadding="0"  cellspacing="0" border="0" >
    <tr align="center">
        <td align="center" >
            <div id="objectDIV" >   
                <object id="workingSWF" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="740" width="600" >
                </object>
            </div>
        </td>
    </tr>
</table>
</body>

The JavaScript code that changes the file is:

function navigateToPage(fileLink) {
    document.getElementById("workingSWF").innerHTML = 
    "<object type='application/x-shockwave-flash' data='"+fileLink+"' width='740' height='600'>";
    document.getElementById("workingSWF").focus();
}

Upvotes: 1

Related Questions