AS3 – Using ExernalInterface.call To Reset JS Timer

I’m trying to build a ‘dead mans switch’ into a flash app. When the app crashes, or slows down significantly, I would like the webpage to refresh. From what I’ve read and seen here, it’s possible to use ExernalInterface to call a resetTimer JS function.

Heres my AS3..

//External Timer and Handler
var externaltimer: Timer = new Timer(1000);
externaltimer.addEventListener(TimerEvent.TIMER, callTimerJS);
externaltimer.start();

function callTimerJS(event : Event):void{
  ExternalInterface.call("window.clearTimeout");
  ExternalInterface.call("timeoutHandle");

}

Heres my JS in my HTML page…

    var timeoutHandle = window.setTimeout(function() {
    window.location.reload(1);
}, 15000);

window.clearTimeout(timeoutHandle);

timeoutHandle = window.setTimeout(function() {
    window.location.reload(1);
}, 15000);

I’m not sure how to test this to verify it’s working. I do know when I build, the webpage refreshes every 15 seconds. I’m not able to get flash to reset the timer.


Source: html

Leave a Reply