2

I know this question has been asked twice on Stack....but I still need help. I have 2 divs each containing SWFObjects. Here's the jquery that shows/hides my Divs:

$(document).ready(function(){ 
 $("#DIV2").hide();

  $('#button1').bind('click', function() {
    $("#DIV1").hide();
    $("#DIV2").show();
  });

  $('#button2').bind('click', function() {
    $("#DIV1").show();
    $("#DIV2").hide();
});
});

But I need my video in DIV2 to STOP PLAYING when it's hidden, and start from the beginning when you show it again. From what I read, I need to remove it from the DOM...but I don't understand how to re-add it. I've seen suggestions for detach(); but can't figure out where my AppendTo() would go.

Can anyone help?? I'd really appreciate it. BTW, here is a related post (which contains a link to ANOTHER related post).

Thank you in advance!

Community
  • 1
  • 1
user576277
  • 71
  • 1
  • 4

2 Answers2

5

Thanks for your help Ben. Before I saw your most recent response, I ended up using what I had seen in an answer to a similar post but adjusted it like so:

 // Remove and re-add video
 var clone = $("#video").clone(true);
 $("#video").remove();
 $("#video-holder").html(clone);

This worked perfectly for me. I gave my swfobject an ID "video", which sat within the div "video-holder". Hope this helps others!

Community
  • 1
  • 1
user576277
  • 71
  • 1
  • 4
0

From my previous experience, detaching DOM elements that contain flash object is very prone to crashing the browser, firefox was particularly vulnerable if i remember correctly.

You could remove the sub elements by doing something like $("#DIV1 OBJECT").remove() and add then again with swfobject when you need them again.

Or, you could use ExternalInterface to try to communicate with your flash objects from javascript.

You're not saying how you play the videos, but if you have your own custom player, you'll need to add some interfaces to your flash file to do that, otherwise, the player you're using might have some existing external interfaces you can use for that.

Ben
  • 20,737
  • 12
  • 71
  • 115
  • Ben - thank you for your response! I want to (and have tried to) take the .remove() route, but I don't understand how I would put it back with swfobject - could you elaborate? That's the key I seem to be missing. Thank you! – user576277 Jan 16 '11 at 16:28
  • var elem = $("#someId")[0]; elem.reload(); I found this - but can't try it until later - is this what I'll need? – user576277 Jan 16 '11 at 16:44
  • If you're using swfobject, you just need to call swfobject again to re-insert the element.. check the swfobject docs http://code.google.com/p/swfobject/ – Ben Jan 16 '11 at 23:48