This question comes up a bit. Up till now I've been telling people to use iframes to do it, but I thought I'd whip up a bit of test file to see if I could do it all on the same page. I did a similar thing using Ajax a while ago, so I thought I'd try a pure client side solution. The below works all the browsers I had access to:
PC: IE 6 IE 7 Firefox 2.0
MAC: Firefox 2.0 Safari Camino Shiira
Now you'll see that I am loading the same dimensioned swf's in my setFlash() function, but you could add extra params to take in w/h, version, colour etc.
function setFlash( loc ) { var so = new SWFObject(loc, "pullContent", "425", "350", "8", "#ffffff"); // wmode opaque needed to make youtube videos scroll correctly // see http://blog.deconcept.com/swfobject/forum/discussion/327/ so.addParam("wmode", "opaque"); so.write("flashcontent"); }
</script>
</head> <body> <div id="flashcontent"> Click a button to load content </div>
function setFlash( loc ) { var so = new SWFObject("swf1.swf", "swf1", "425", "350", "8", "#ffffff"); var so = new SWFObject("swf2.swf", "swf2", "425", "350", "8", "#ffffff"); var so = new SWFObject("swf3.swf", "swf3", "425", "350", "8", "#ffffff"); // wmode opaque needed to make youtube videos scroll correctly // see http://blog.deconcept.com/swfobject/forum/discussion/327/ so.addParam("wmode", "opaque"); so.write("flashcontent"); }
</script>
</head> <body> <div id="flashcontent"> Click a button to load content </div>
function setFlash( loc ) { var so = new SWFObject(loc, "pullContent", "365", "452", "8", "#ffffff"); // wmode opaque needed to make youtube videos scroll correctly // see http://blog.deconcept.com/swfobject/forum/discussion/327/ so.addParam("wmode", "opaque"); so.write("flashcontent"); }
</script>
</head> <body> <div id="flashcontent"> Click a button to load content </div>
What you wrote earlier ("so how do i make say 3 swfobjects from my swf in my root") sounds like you're trying to load a SWF into another SWF.
SWFObject is designed to embed a SWF onto an HTML page, and to pass variables during the load process. SWFObject can't be used to pass variables at any time other than when it first loads.
If you're trying to load a SWF into another SWF, you should use your form ("form1") to communicate with the container SWF. Flash's ExternalInterface Class enables you to set up two-way Javascript-Actionscript communication (a great example is at http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_15683).
If you meant that you want to replace the SWF embedded on your HTML page with another SWF, you'd continue to use Aran's example posted above.
Some notes: Check your filepath... is 'swf1.swf' the correct filepath (no nested folders?).
Your button names and values are conflicting: <input type="button" name="Button2" value="content 2" onClick="javascript:setFlash('swf2.swf');"> <input type="button" name="Button2" value="content 2" onClick="javascript:setFlash('swf3.swf');">
The last one should be: <input type="button" name="Button3" value="content 3" onClick="javascript:setFlash('swf3.swf');">
Actually, you don't need to use "javascript:" in an onclick call... just put your function: onClick="setFlash('swf1.swf');". So your buttons should look like this: