tags:

views:

157

answers:

3

I am trying to develop a way to change a flash file displayed on the screen to another file by clicking a button. I have been able to do this with jpg images, but I can't get it to work with flash files. Can anyone help? I would greatly appreciate it. Below are two html's: the first one changes jpg images and it works, the second one I constructed to be similar to do the same with flash files but it does not work.

//Html 1. This changes Image 1 to Image 2 on click. It works

function changeSrc() { document.getElementById("myImage").src="Image 2.jpg"; }



//Html 2. This is intended to change Flash 1 to Flash 2 on click. It does not work

function changeSrc() { document.getElementById("myImage").src="Flash 2.swf"; }



+1  A: 

here you have an example of changing the flash embedded im js:

function setFlashSrc(newSrc)
    {
          var flash='<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" WIDTH="210" HEIGHT="210">';
          flash+='<PARAM NAME=movie VALUE="'+newSrc+'"><PARAM NAME=quality VALUE=high>';
          flash+='<EMBED SRC="'+newSrc+'" QUALITY=high PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ';
          flash+='TYPE="application/x-shockwave-flash" WIDTH="210" HEIGHT="210">';
          flash+='</EMBED>';
          flash+='</OBJECT>';
          document.getElementById("urgeo").innerHTML=flash;
    }
mapache
+1  A: 

You need to use the name property of the embed or object tag to grab a reference to your embedded flash files. Using the id will not work.

But there is an easier way of doing this. if you use swfObject to embed your swfs, this can be as simple as one javascript call.

<script type="text/javascript">

var flashvars = false;
var params = {
  menu: "false",
  flashvars: "name1=hello&name2=world&name3=foobar"
};
var attributes = {
  id: "myDynamicContent",
  name: "myDynamicContent"
};

swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0","expressInstall.swf", flashvars, params, attributes);

</script>
picardo
A: 

Thankyou thankyou thankyou. A million love hearts and a moon of goodness to you all. 4 hours of searching and failing. And I have flu....

I love you :) xxxx

Peter Mead