Jeton R.
Jeton R.

Reputation: 395

Change Parameter Value with javascript

I have the ffmp3 embed code and was trying to change the flashvars parameter value with javascript is that possible?

I came so far but no luck:

 <a id="foo" href="#">Change Radio</a>

    <object width="205" height="109" bgcolor="#FFFFFF">
      <param name="movie" value="ffmp3-config.swf" />
      <param name="flashvars" value="Radio1" />
      <param name="wmode" value="transparent" />
      <param name="scale" value="noscale" />
      <embed src="ffmp3-config.swf" flashvars="url=Radio1" width="205" scale="noscale" height="109" wmode="transparent" bgcolor="none" type="application/x-shockwave-flash" />
    </object>

<script type="text/javascript">
    var foo = document.getElementById('foo');
    foo.onclick = function () {
        document.getElementsByName('flashvars')[0].value='Radio2';
    }
</script>

Upvotes: 0

Views: 5536

Answers (3)

Sergio
Sergio

Reputation: 28845

This actually works as it is (check here). Your problem might be that the flash object is already rendered and will not use the changed value, so you need to "re-load" it after changing value.

document.getElementsByName("flashvars")[0].value = 'newvalue';

Upvotes: 0

dognose
dognose

Reputation: 20909

In short: yes, it is possible to change any HTML-Elements value with Javascript. But i guess, that this might not help you in the way you expect.

The Flashplayer Object will most likely only query the params, when its loaded for the first time. Therefore changing a param, while the flashplayer is running might not affect its current stream.

But this can also be solved:

  • Either place ALL Available Objects during the first page load (hidden), set autoplay to false, hide/unhide objects as required, and trigger the start using javascript.

  • Not only change the flashvars element using Javascript, but generate the "complete" Flashplayer Object dynamically as required.

  • Directly modify the flashplayers url, instead of the params

  • ... be creative :)

Upvotes: 1

giorgio
giorgio

Reputation: 10212

works like a charm, nothing wrong with your code

but the problem is not that the value isn't being changed, but that the flash object doesn't know about the changes. It just instantiates at page load and has no link with the html code anymore. You'll have to rewrite the whole object block I think (with document.write, or if you want to be kind for yourself, using jquery or any other library)

Upvotes: 1

Related Questions