Destroy a flash object created with SWFObject

flashswfobject

I am using YUI's Dialog control to show a Flash movie on my site in a popup.

I am creating the Flash control using SWFObject. This creates a JW Player instance for my video.

I was quite surprised to see no easy way to destroy the movie in the SWF Object FAQ. When the YUI panel destroys itself it leaves an orphaned video playing.

What is the best way to destory a SWF control that was created with SWFObject, or is there no good way and I ought to just hide it instead and call 'stop()' ?

Best Solution

swfobject.removeSWF("myVideoPlayer");

--

Edit: this kills off the original <DIV> that you used to create the swfobject in the first place.

So if you need to recreate the Flash again you'll need to insert a new placeholder <DIV>.

<!-- you'll need to wrap the 'myVideoPlayer' DIV in another DIV -->
<div id="videoPlayerWrapper">
   <div id="myVideoPlayer"/>
   <a href="#" class="close">Close Player</a>
</div>

swfobject.removeSWF("myVideoPlayer");
$('#videoPlayerWrapper').prepend("<div id='myVideoPlayer'></div>");

Related Question