Thursday, March 1, 2012

Two Classes Every JWPlayer AS3 Plugin Developer Should Use

I wanted to share two classes that are part of the JWPlayer package that I strongly recommend every JWPlayer AS3 plugin developer at least try. Hopefully you will find them as helpful as I did:

LOGGER (com.longtailvideo.jwplayer.utils.Logger):
If you're looking for a robust tool to help debug your plugins, I can't think of anything easier than Arthropod. When you use the Flash debugger player, you get a new menu item (added by the JWPlayer) which allows you to export your logs to a choice of options: arthropod, console or trace. Enabling this on it's own will provide a nice bit of feedback but wouldn't it be great to have your own custom methods pass debugger information? You can with Logger.

Logger takes two parameters, the value you want to expose and an identifier (such as the class or method you're calling from). If you leave the second parameter out, Logger simply uses LOG instead. Here's how I set up a custom method to call Logger within my own plugin:

public function debug(debugMessage:String, debugType:String=null):void{
    if(debugType == null){
        Logger.log(debugMessage);
    }
    else{
        Logger.log(debugMessage, debugType);
    }
}

ROOTREFERENCE (com.longtailvideo.jwplayer.utils.RootReference):
This one is pretty self explanatory. If you need a reference to the root object to set event listeners, instead of trying to reverse engineer the logic and find just the right object, simply import this class and reference RootReference. Bam, done; it's that simple. Here's how I implemented it:

RootReference.stage.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent):void{
    if(e.keyCode == 32){
        //the space bar was pressed
    }
});


I hope this helps!

No comments:

Post a Comment