Event-Based LMS / Flash Communication

Those who work in the eLearning field, know that Flash SCO (Shareable Content Object) to LMS (Learning Management System) communication is an ugly mess. The SCORM RTE specification requires JavaScript as the communication bridge between a SCO and and the LMS. JavaScript is asynchronous in nature which means that any time you make a request for information from the LMS you must enter into some type of “loop” waiting for a response–typically this takes the form of an interval, or a frame based loop. In the past I’ve used setInterval to evaluate whether properties returned from the LMS have changed, but this always felt rather ugly to me so I decided to implement an event based system which uses Object.watch and EventDispatcher. Here’s what I came up with:

/**
* @author Paul Brooks Andrus
* Creative Commons License
* http://creativecommons.org/licenses/by/2.5/
* This work is licensed under a Creative Commons Attribution 2.5 License
* June 6, 2005
*/

import mx.events.EventDispatcher;
import mx.utils.Delegate;

class Watcher {

function dispatchEvent(){};
function addEventListener(){};
function removeEventListener(){};

function Watcher() {
EventDispatcher.initialize(this);
}

/*
* Creates a watched property using the scope of the first parameter
*
*/
public function watchProp(s:Object, p:String):Void {
s.watch(p, Delegate.create(this,returnProperty), s);
}

/*
* Removes watch from the scope defined by the 4th parameter, returns
* the value of the watched property and dispatches an event object
* with all the information from the watch
*
*/
public function returnProperty(p:String,ov:String,nv:String,s:Object){
s.unwatch(p);
dispatchEvent({type:"change", prop:p,value:nv,old:ov});
return nv;
}
}

The solution, as you can see, is simple, reusable, very clean and allows the use of the familiar event-listener model. You can download the source here.

9 Comments

  1. Posted July 8, 2005 at 4:10 pm | Permalink

    This is pretty similar to the ideaa I used in ADL’s Plug-in Technology Example (http://www.adlnet.org/downloads/201.cfm). In the example, I used ASBroadcaster (because I’m old school), but when I have the time and the motivation, I’ll probably switch to EventBroadcaster, or possibly contain the JavaScript transaction watching by using the EventDispatch as noted here.

    Nice work!

    -a-

  2. Posted May 12, 2007 at 11:56 pm | Permalink

    Hi

    I am looking for a flash sample that can demonstrate the scorm 2004 communication . There was a sample scorm demonstrator for flash at ADL site but it was meant for scorm 1.2, where as I need a sample for flash sample that will demonstrate hopw the get and set values are used in scorm 2004 environment. I will appreciate if you can help me in this.

    with regards
    Samir

  3. Posted May 13, 2007 at 10:50 am | Permalink

    Hey Samir,

    There are some pretty good examples of Flash and SCORM 2004 on the ADL website that Aaron Silvers put together during his stint there. Here’s one example I found on the ADL site:

    http://www.adlnet.gov/News/articles/index.aspx?ID=312

    I’ve done work for TechSmith with SCORM 2004, but it involved fairly basic conformance–scoring and interaction. The Flash piece simply called the initialize / terminate functions and simply passed out a score to a JavaScript function that then called the JavaScript LMS wrapper. What I’m saying is you’re more than welcome to download Camtasia Studio, produce a SCORM 2004 module and take a look at the JavaScript produced by Camtasia to see this in action.

  4. Posted May 30, 2007 at 3:33 pm | Permalink

    You might enjoy the new LibSCORM library:
    http://sourceforge.net/projects/libscorm

    It provides a SCORM Flash content template that does all the work communicating with an LMS.

    From the project description, “Library to assist e-Learning content developers in creating SCORM-conformant courses. Implements common shareable content object tracking and communication functionality. Features like timing, bookmarking, and navigation are built in.”

  5. Pxl
    Posted October 3, 2007 at 11:56 am | Permalink

    Doing a Js/As client is actually not really hard if you follow the ADL rulez and Internet have some documents on it . The real problem is to implement a Js/ActionScript system in a custom LMS server . How ? Wich langages ? I actually work on it , and only ASp intersting me , and i don’t find any exemples on a JS client comunicating with a others servers . If you have any informations about this , link it ! the only way i find suxx totaly , based on post to the server and querystring for informations from the server.

  6. Josh Sprague
    Posted November 1, 2007 at 5:32 pm | Permalink

    Amazing stuff my friend! I’m hoping this will help us with some problems…

    hope you are well!

  7. Stuart
    Posted November 26, 2007 at 11:17 pm | Permalink

    Hi. I’m developing SCOs using Flash CS3 and Reload Editor and I have the whole process working apart from one little bug and I thought you might be able to help.

    I have 11 sections to the SCO. The first is a slide show of information. The next button on the last slide of this first SCO opens the next .swf which is a Quiz. This pattern (slide - quiz - slide) continues through the SCO. I’m using Moodle as my LMS. My problem is that although the swf’s will go slide - quiz - slide, the LMS won’t register it. It will only register the last section of the SCO that is done, so the users grade ends up only being for the last Quiz section that they did (so they get 12% right as appossed to the 100% they actually got) I know i sound confusing so to give you an idea, here is the code from the last next button on the first section of slides that opens the first Quiz (’LoadQuiz’ is the variable name of the next button and ‘2 - Quiz.swf’ is the name of the Quiz file);

    LoadQuiz.onRelease = function() {
    unloadMovieNum(_root);
    loadMovie(”2 - Quiz.swf”,_root);
    SetValue( “cmi.core.lesson_status”, “completed” );
    }

    As will most SCO’s and the examples I’ve got from ADL, You can click on the title of the next section after you complete the previous one, but my boss doesn’t want to give the user that sort of control. I need to be able to make it (which I’ve done) go back to the beginning of the previous section of slides if they get one of the quiz questions wrong so they read over the information again.

    Simply put, I’m trying to make it so the user thinks its one long flash file instead of the 11 files that it is. But I’m stuck on how to tell the LMS from the flash file that they have finished this section of the SCO.

    I have tried to use the command ‘terminate ();’ but it didn’t seem to work. If you can help me out here I would be most grateful.

  8. Posted November 12, 2008 at 6:59 pm | Permalink

    Hi Brooks

    I stumbled onto this post while doing some SCORM searches today. I thought it might be helpful for your readers to know that the approach you described here was very useful for its day (probably even cutting edge when you wrote it), but has become obsolete with ExternalInterface.

    I’m not trying to self-promote, but if anyone would like to use ExternalInterface with SCORM, I’ve created SCORM ActionScript classes (both AS2 and AS3) that handle LMS communication synchronously using ExternalInterface and JavaScript. They work in Flash and Flex.

    Thanks! :)

  9. Posted November 13, 2008 at 8:49 am | Permalink

    @ philip - you’re absolutely right. This approach is, well, very dated to say the least.

    I definitely encourage everyone hitting this link to check out the links Philip posted. He’s an elearning developer who is actually working in the trenches (my eleaning involvement has been sporadic for the last several years).

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*