Grant Skinner

The "g" in gskinner. Also the "skinner".

@gskinner

FAVideo Released: Flash Video for JavaScript / AJAX

We had the pleasure of working with Adobe to architect and develop the FAVideo component that Kevin Lynch demoed at AJAXExperience, and which was just released in beta form on the Adobe labs site. It was an interesting project, building a Javascript object that acted as a facade for an embedded Flash video player, and using external interface to communicate between them. The intent is to provide a simple interface for AJAX / Web2.0 developers to embed, control, and play video back in their applications. As such, it has a really robust API for controlling video playback, but it also provides a really simple way for anyone to quickly inject video into their HTML content.

<script lang="javascript">
// simple usage:
var myVideo = new FAVideo("myDiv", "myVideo.flv");
// or a little more customized:
var opts = {skinPath:"SteelOverAll.swf", autoLoad:false, previewImagePath:"preview.jpg"};
var myVideo = new FAVideo("myDiv", "myVideo.flv", 320, 240, opts);
</script>

We had to write some interesting logic to deal with delaying method calls while the player SWF loads, as well as writing a custom event model for subscribing to events like cuePoint, progress, and playheadUpdate in Javascript. We also included support for using any Flash 8 video player skin, youtube-style preview images, built-in Flash player detection, and a ton more. Building the Javascript portion of this component was a somewhat nostalgic experience for me, hacking out classes using prototypes. Made me even happier about AS2 & 3.

The trickiest part of the whole thing was getting it to work properly in Internet Explorer. Apparently there’s a series of nasty issues with IE, Flash player, divs and innerHTML – but that’s a topic for another post.

FAVideo is released under a BSD license, so it can be used for commercial projects. You can download the full source on Adobe Labs. Thanks to everyone at Adobe that tested and provided feedback on the component!

The Paperless Office: Fact or Fiction

I try to run a fairly environmentally conscious office. We recycle everything possible, use low-power CLF lighting, work on laptops and LCD monitors exclusively (with the exception of our server), and only turn on the (water cooled) AC when we really need it. We’re not exactly “cutting edge” on the environmental front (like Adobe for instance), but I try to do what we can.

It occurred to me today that the one area that we have been really successful is in paper use. We are essentially a paperless office. We don’t even have a printer in the office, and I don’t really miss it. Documents are all passed around electronically via an interesting combination of SVN, file sharing, email, and bluetooth. Everyone has a second monitor, so it’s usually fairly easy to reference one document while working on another. The only real paper we use is notepads that people use to sketch ideas and take notes. Even that is being partially replaced by tools we’ve built in-house like “gTimer”, gTodo, gDocs (our internal shared notes tool), and others.

I’m lucky right now because my condo is only a minute away from the office, so the occasional item that really needs to be printed (contracts mostly) just gets printed at my place and walked over. I think when we move I’ll set up a printer in the office, but keep it off the network to minimize the temptation of printing things off for quick reference.

I thought this was kind of interesting, because it made me think back to my first web job where we printed mountains of documents, and this was during the height of the “paperless office” hype. I’d be interested to hear if other people are also finding that their dependency on paper is decreasing as screen resolutions increase and the technology for sharing and organizing documents gets better.

Yggdrasil 3D: World Tree in Papervision 3D and AS3

I’ve been meaning to play with Papervision for awhile, but haven’t found the time. I finally squeezed in a little time to tinker, and the result is Yggdrasil 3D. The Yggdrasil is the world tree in Norse mythology that spans the underworld, earth and the heavens.

The scene is generated entirely programmatically (no prebuilt textures or models). Parts of it were harder than I expected, but I’m starting to get a good grip on it, and plan to do a series of experiments in ActionScript 3 and Papervision 3D.

Continue reading →

Building a Static EventDispatcher in AS3

One of my favorite features of AS3 is the low-level inclusion of EventDispatcher in the AS3 framework. I do not miss the days of including EventDispatcher mix-ins in 80% of my classes in 100% of my projects. I especially like the additional features of the AS3 EventDispatcher: cancellation, custom event types (built in), preventDefault, event phases, etc.

However we have had several AS3 projects that have had a need for an EventDispatcher that is not instance-based. So, without further ado, here is an approach that we have used since our AS2 days:

package {
import flash.events.EventDispatcher;
public class MyClass {
protected static var disp:EventDispatcher;
public static function addEventListener(...p_args:Array):void {
if (disp == null) { disp = new EventDispatcher(); }
disp.addEventListener.apply(null, p_args);
}
public static function removeEventListener(...p_args:Array):void {
if (disp == null) { return; }
disp.removeEventListener.apply(null, p_args);
}
public static function dispatchEvent(...p_args:Array):void {
if (disp == null) { return; }
disp.dispatchEvent.apply(null, p_args);
}
// Other class code
}
}

Note that this differs from a Singleton approach, in that I didn’t want to force a user to extend EventDispatcher (plus I dislike getInstance()). Additionally, some of my fellow developers have noted that using the apply syntax instead of defining all the arguments with types is lazy. Since this runs through an actual EventDispatcher instance, and this class is just a proxy, I didn’t think they were necessary.

I hope someone out there finds this useful. Internally we use it quite often – and it seems to be the most reliable way to add static-access events to a class.


Update
Since I was scolded for not typing the arguments, here is an update, and a sample usage.

package {
import flash.events.EventDispatcher;
import flash.events.Event;
public class MyClass {
protected static var disp:EventDispatcher;
public static function addEventListener(p_type:String, p_listener:Function, p_useCapture:Boolean=false, p_priority:int=0, p_useWeakReference:Boolean=false):void {
if (disp == null) { disp = new EventDispatcher(); }
disp.addEventListener(p_type, p_listener, p_useCapture, p_priority, p_useWeakReference);
}
public static function removeEventListener(p_type:String, p_listener:Function, p_useCapture:Boolean=false):void {
if (disp == null) { return; }
disp.removeEventListener(p_type, p_listener, p_useCapture);
}
public static function dispatchEvent(p_event:Event):void {
if (disp == null) { return; }
disp.dispatchEvent(p_event);
}
// Public API that dispatches an event
public static function loadSomeData():void {
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
MyClass.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
function onComplete(p_event:Event):void {
trace("Complete!");
}
MyClass.loadSomeData();

AIR Panel for Flash CS3 Updated

We’ve updated our panel for testing, configuring and packaging AIR applications in Flash CS3. The most significant updates are the addition of a setting for window mode (system or transparent), and support for XML round-tripping, so edits/additions to the AIR application XML file will be preserved.

We’ve also tweaked the interface, and made some other minor updates. Click over to the original post for installation instructions, and a download link. Please use extension manager to remove the previous extension prior to installing this version! Everything should still run ok, but removing the old version in the future may cause problems.

We think we’ve also isolated the issues some people were having with packaging to a bug in the JSAPI, and have added troubleshooting information about this to the end of the original post.

Thank you to everyone who tested it, and provided feedback! Please continue to do so.

Creating AIR Projects with Flash CS3


UPDATE: Official Adobe AIR support, August 21

Adobe has released official support for AIR in Flash CS3. We’ll keep the AIR panel available, but it’s unlikely it will be updated any further. Get the Flash CS3 update for AIR.


Currently, you can only create AIR (formerly Apollo) applications with FlexBuilder. Adobe has already announced that they will be adding support to Flash CS3 to create AIR projects, but we wanted a solution in the meantime. As such, we’ve extended the work that Guy Watson began with his “Test in Apollo” jsfl command, and built a panel that lets you test, configure and compile AIR applications from within Flash CS3.

Continue reading →