View Full Version : how do you change the src value in the embed command and show it instantly?

10-23-2005, 01:49 AM
i have been fighting with this for days now and i cannot figure out how to change a diplaying flash file on a page with a link or a button. i can display the flash file with the <embed src="flash.swf" name="flashdisplay"> but i cannot get the src to change like the Image Flip in Javascript.

when the user clicks on "Next", the displaying flash file will change to a different one that is already uploaded to the server....without refreshing the page

Can some one help!

10-23-2005, 08:47 PM
You could place a <span> tag around the embed tag. Then just create an image or button that includes an onclick event and create a function that will change the innerHTML of the span tag.

If that doesn't work you could try using the getelementbyid command and setting the src to a different file. You may have to refresh though for this option to work.

//option 1
function changeEmbed() {
document.getElementById('flash').innerHTML = "<embed src='newfile.swf' name='newfile'></embed>";

<span id="flash">
<embed name="original.swf" name="original">

<img src="next.gif" onclick="changeEmbed()">

//option 2

<embed src="oldfile.swf" name="oldfile" id="oldfile"></embed>

10-24-2005, 01:59 AM
I got it to work by using IFrames :) and the getelementid thing.

12-06-2005, 05:36 AM
except the src is an mp3 file in the <embed></embed>..... I try to change the src using
getElementById('name').src="name.mp3" and then using onclick="functionname()" but I always get an error...

I also tried using .innerHTML="" to change the html in my <div></div> but I keep getting the following error:

Error: Unterminated string constant

I made sure that the html within the .innerHTML="" does not have an " in it and if its needed I replace " with '. So can anyone u tell me whats wrong?

12-06-2005, 05:44 AM
Here is the javascript code:

function Scar()
document.getElementById('embed1').innerHTML="<embed src='http://apollo.bluelaguna.net/ccmusic//01%20-%20Chrono%20Cross%20~%20Time's%20Scar.mp3'
width='140' height='40' autostart='true' loop='TRUE'>

Here is the onclick and <div>:

<p onclick="Scar()">Scar</p>
<div id="embed1"><embed src="http://www.ocremix.org/songs/Chrono_Trigger_Far_Away_Memories_OC_ReMix.mp3" width="140" height="40" autostart="true" loop="true">
</embed> <br>
<font size=1>You are listening to "Far Away Memories" remix from www.ocremix.org . You have the option to turn the music off at any time.</font>

12-06-2005, 06:08 AM
Search in the multimedia forum for a thread titled Embedded Windows Media Player you will find a thread that has a discussion on exactly what you are trying to do.