0

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>
2
  • You also have to change the embed tag. However, just changing the attribute would likely not do anything, you'd have to create a new element with the new settings for it to take effect Commented Jul 18, 2013 at 8:55
  • Actually it works as it is, check here jsfiddle.net/adBkH/1 Commented Jul 18, 2013 at 8:56

3 Answers 3

1

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 :)

Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

0

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';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.