Daniel O
Daniel O

Reputation: 4634

Update flashvars and reload flash with jQuery

I would like to update the flashvars value argument to view another video:

<param name='flashvars' value='movieId=1002' />

I found out that I can make it work in Firefox by updating the parameter with the extra step of readding the whole flash contents.

$("param[name=flashvars]").attr("value", "movieId=33");
$("embed").attr("flashvars", "movieId=33");
$(".root").append($("#video"));

But this does not work in IE8 as the browser won't refresh the flash contents. Any ideas on how to reload the flash contents without external dependencies like swfobject.js?

Upvotes: 9

Views: 13206

Answers (5)

cloakedninjas
cloakedninjas

Reputation: 4216

// update flashvars
var fv = 'foobar=1';

$("object param[name='flashvars']").attr("value", fv);
$("embed").attr("flashvars", fv);

// create new object to hold it     
var obj = $("object");

// remove existing Flash from DOM
$("object").remove();

// add new HTML to DOM
$("#mviewer").append(obj.html());

Upvotes: 4

matthewwithanm
matthewwithanm

Reputation: 4152

If you want to change the flash vars and reload the Flash, you should just remove the SWF from the DOM and embed it again with your new vars (using SWFObject or whatever other method suits your fancy!).

If you want to change the flash vars without reloading the Flash, you're out of luck: there's no officially-supported way. In this case, you should use ExternalInterface to call ActionScript methods that update your values from JavaScript.

Upvotes: 3

Natim
Natim

Reputation: 18132

Actually, why not use swfobject.js ?

I did like this :

   <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
   <script type="text/javascript" src="js/swfobject.js"></script>

   <div id="qsound"></div>

<script type="text/javascript">
   if(q.sound) {
    swfobject.embedSWF("js/dewplayer/dewplayer.swf", "qsound", "60", "20", "9.0.0", false, {'mp3': 'sounds/'+q.sound}, {'wmode': 'transparent'});
    $('#qsound').show();
} else {
    $('#qsound').hide();
}
</script>

Upvotes: 0

Benjamin Allison
Benjamin Allison

Reputation: 2154

I'm curious about this too. I'm trying to send a new string via flashvars to a SWF that I have no opportunity to change, and just changing the flashvars with jQuery, without having to use externalinterface, is the best option.

Upvotes: 4

PatrickS
PatrickS

Reputation: 9572

Instead of using flashvars, you could use the ExternalInterface AS3 class to send the new value to Flash.

ExternalInterface allows for a two way communication between AS3 & Javascript

Upvotes: 0

Related Questions