views:

238

answers:

1

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 mehtods 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!

Thanks in advance.

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.

A: 

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.

Jasper De Bruijn
I like your way of doing it, but sadly it had no effect on my error. I tried both solutions but the error still occurs.
Indyber