Instantiate one Flash object at once in a page

Senario:

I need to instantiate only one Flash object at once in a page, for instance under a row of tabs when the user clicks on one of them. Sometimes I toggle between different Flash objects; sometimes just another DOM div takes place of the Flash object. It’s very straightforward in Firefox since all you need to do is to toggle the “display” property (set it to the value of “none”). With Prototype library, you can use Element.hide()/show(). In IE, situations get a little complicated since if that Flash is playing a video clip, the stream continues (you still hear sound, etc.) regardless of its containing div’s “display”/”visibility” property values.

Solutions:

For the former situation, simply write a new swf object to the same div:

function loadSWF(fileName)
{
swfURL = appURL+’swf/’+fileName+’.swf’;
var so = new SWFObject(swfURL, “soObj”, “500”, “360”, “8”, “#eeeeee”);
so.addParam(“allowscriptaccess”,”always”);
so.addParam(“swliveconnect”, “true”);
so.useExpressInstall(“http://myhostname.com/js/swfobject/expressinstall.swf”);
so.write(“vidHolder”);
}

For the latter situation, destroy the swf object by doing the following when toggling to another div which doesn’t contain any swf object. This will stop the audio/video streams:

$(‘vidHolder’).innerHTML = “”;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: