Monthly Archives: June 2005

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.

Eclipse ASDT Editor Templates

I must confess that I’ve been an avid Flash blog reader for some time now, but had been too lazy (and perhaps a bit insecure) to set my own up. However, I realized the time had come when I started emailing Jesse Warden aka Jester XL with “ideas” for him to blog–Jesse’s response was, per norm, funny as hell, “dude, blog it yourself.” And so here I am posting the “blog idea” that I was pestering Jesse with.

Like many in the Flash community, I began playing around with the Eclipse platform, ASDT editor, MTASC and Flashout (“FAME” ala Jesse) back in March following Carlos Rovira’s excellent article detailing installation, configuration and use. However, as someone with a primarily Flash background who had lived in the Flash IDE exclusively I found many aspects of Eclipse to be a bit daunting (the dreaded IDE learning curve), but after several months of exploration the light finally came on and I’ve gotta say Eclipse rocks! There are many reasons why I’ve totally fallen for this platform, but today I’d like to discuss ASDT editor templates (I’ll be extracting portions of the email exchange with Jesse on this topic so note the context).

Editor templates are simply code templates which can be invoked by typing in a shortcut command (i.e. “singleton” or “class”) and hitting CTRL+ SPACE on your keyboard. The are some useful default templates which are part of the ASDT plugin editor, but I’ve found that everything really needs to be modified to taste and customized to reflect user specific attributes. As I said to Jesse, “I’ve been using Flash in Eclipse for almost 2 months and I know it was not readily apparent how to use the shortcut commands, or how to edit and create new templates. Now that I’ve figured them out and begun using them, it has further cemented my love for the ASDT editor.” I also included a rather quick and dirty Captivate tutorial, found here, which detailed where to find the editor templates, how to modify existing templates, create new templates and use them in your code.

As an example, here’s template code which creates the class structure with the EventDispatcher mixin included:


/**
 * @author Paul Brooks Andrus
 * Copyright BadAttitude Productions
 * ${date}
 */ 

import mx.events.EventDispatcher; 

class ${enclosing_package_and_type} { 

     function dispatchEvent(){};
     function addEventListener(){};
     function removeEventListener(){};
                 
    /**
     * Constructor
    /*
     function ${enclosing_type}(${cargs}) {

        EventDispatcher.initialize(this);
        ${todo}

    }
        ${cursor}
}

The nice thing about the templates is not only do they save you a ton of typing, but you can also use variables which are represented by the styntax ${variable name}.

Another thing everyone should do is look at the Java editor templates and mine them for goodies (as an example, I took the switch statement template and modified it to taste).

Eclipse is a very powerful platform with a plethora of rich features, of which I have discovered but I few–Working Sets are awesome–and I hope some of you benefit from my learning curve. If you have other insights I would love to hear about them.