javascriptgoogle-chromeinternet-explorerflashswfobject

SWFObject event undefined in Chrome works in IE


I want to get the currentFrame of my Flash movie when it is loaded. I followed the the tutorial found here http://learnswfobject.com/advanced-topics/executing-javascript-when-the-swf-has-finished-loading/index.html and SWFOBJECT CurrentFrame Javascript. I am using SWFObject 2.3 beta. This works perfectly fine on Internet Explorer however it does not work on Google Chrome.

In Chrome I get the error

Uncaught TypeError: e.ref.currentFrame is not a function

Checking e it returns [object Object] Checking e.ref returns [object HTMLObjectElement] Checking e.ref.totalFrames returns undefined

var flashvars = {};
var params = {};
var attributes = {};
function mycall(e){
    setInterval(function(){console.log("Frame: " + e.ref.currentFrame)},1000);
}
swfobject.embedSWF("notmyswf.swf", "course", "100%", "100%", "6.0.0", false, flashvars, params, attributes, mycall);

Why is this not working on Chrome but works well with IE? Is the event e not detected? Is there a work-around on how to make this work on Chrome?

The purpose of this is for me to create a check if the user is really using the course he has opened and not just leaving it idle. I have already added a code that will check idle but it is not enough. Most learners, have figured out a way to just open a course, leave it there to accumulate hours of training. Some even have a program running in their computers that will just move the mouse 1-pixel every few seconds so that the computer does not go to idle. If I can check the current frame of the Flash movie, I can create a function that will calculate the current page the user is viewing every 15 minutes. If he is stuck in the same page I can then show a prompt that the user must click in order to continue viewing the course or it will automatically close.


Solution

  • I suggest dropping the SWF-based currentFrame approach in favor of monitoring your calls to the database using JavaScript. (Based on your comments, it sounds like the DB calls are being sent by JS, so this shouldn't be a problem.)

    If the course bookmark is auto-saved every 3 minutes (as described in your comments), you can cache the value in your page's JS and do a compare every time the save is performed. If the value hasn't changed in x number of minutes, you can display your timeout warning.

    If you're using a SCORM wrapper (or similar), this is really simple, just modify the wrapper to include your timer code. Something like:

    //Old code (pseudocode, not tested)
    function setBoomark (val){
        API.SetValue("cmi.core.lesson_location", val);
    }
    

    //New code (pseudocode, not tested)
    var current_location = "";
    
    var activityTimer;
    
    function disableCourse(){
        //do stuff to disable course because it timed out
    }
    
    function setBoomark (val){
        API.SetValue("cmi.core.lesson_location", val);
        if(val === current_location){
            //do nothing, timer keeps ticking
        } else {
            //reset timer using new bookmark value
            if(activityTimer){ clearTimeout(activityTimer); }
            activityTimer = setTimeout(disableCourse, 15000);
            //Update current_location value
            current_location = val;
        }
    }
    

    This is a rough sketch but hopefully you get the idea.