Reputation: 35
I'm creating a quiz and as a timer in the quiz I have a flash movie (an animated clock). I poll the clock every second to see if the time for the quiz has run out.
The code for this functionality looks like this: (simplified)
$(window).load(function() {
var flashMovie = getFlashMovieObject(flashId);
var timeElapsed = flashMovie.GetVariable("timeElapsed");
var timeSet = flashMovie.GetVariable("countdown");
var degrees = flashMovie.GetVariable("degrees");
var timerStatus = flashMovie.GetVariable("timerStatus");
});
First of all, it just fetches the flash movie object, and then calls some methods on the object. This works fine in Firefox (pc & mac), Safari (mac) but in IE8 on pc it returns 'unexpected error on line 3' (or any other line that uses the flashMovie object).
The code for the getFlashMovieObject() function looks like this:
function getFlashMovieObject(movieName)
{
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return window[movieName];
}
return document[movieName];
}
Any help is appreciated!
UPDATE: I have figured out that if set IE8 clear the cache for each reload, then this occurs. If I don't, then it only fails the first time, and all subsequent reloads work fine. I don't understand how the cache can resolve this issue.
Upvotes: 1
Views: 1640
Reputation: 15560
At a wild guess, IE is incorrectly firing the window.load event too early, before your swf is fully loaded. That might explain why clearing your cache forces the error.
If you're not already doing so, use SWFObject to embed your Flash, then you can use the loaded callback to know when your Flash object is really available.
Upvotes: 0
Reputation: 1444
In my experience, the getFlashMovieObject function has some quirks in some browsers, and I found several versions of it. This one seems to fair pretty well in most browsers:
function getFlashMovieObject(movieName){
if(document.embeds[movieName])
return document.embeds[movieName];
if(window.document[movieName])
return window.document[movieName];
if(window[movieName])
return window[movieName];
if(document[movieName])
return document[movieName];
return null;
}
If you happen to use jQuery, I found that something as simple as
$("#flashobject")[0].GetVariable("timeElapsed");
seems to work on every browser.
Upvotes: 1