Javascript – Executing SWFObject with Ajax reloads

ajaxflashjavascriptswfobject

For my current project I am working on a home page that has a series of tabs above a content box that each execute an ajax script to load new content into the content box. However, some of these pages contain a flash object called with SWFObject and when the ajax script calls the page, the SWFObject javascript is not executed and I am left with the no flash support error message.

I have tried defining a function for each video call (short of just designing a single function and passing variables to it) and having the function be called as part of the ajax function but I am left with the same results.

Any ideas how to solve this? I am not opposed to using something other than SWFObject though I have been lead to believe it is the best solution currently. All help is sincerely appreciated.

Best Answer

edit: I misunderstood the question... let me reanswer:

The problem is when the content is returned the scripts aren't run at all.

Case A: You are in control of the pages content / javascript (which it sounds like)

You should provide a means of callback once those pages are loaded to start executing your SWFObject embeds.

it could look a little like this (on the page with flash)

function loaded()
{
    swfobject.embedSWF("myContent.swf", "flashContent", "300", "120", "9.0.0");
}

and on the shell page

//note the jquery dependency
$.post('url', function(data)
{
    $(myDiv).html(data);
    loaded();
});

Case B: You do not have control of those pages...

Some libraroies (jquery might be excluded) allow 'run scripts' as an option... I'm pretty sure they parse out the script tags and eval(...) them - I would strongly suggest against this, but it's worked for me in the past.