Flash 11 should be a switch to JavaScript
Flash 11 should be a switch to JavaScript
Let's press the reset button and drop ActionScript. It hold no relevance or advantage in todays world.
Over the past few months I've been working closely with JavaScript in different environments outside of the HTML DOM. Two of those being on the server side - Node.js and CouchDB. The other being an experimental front-end, RIA like platform. And what I've concluded over these past few months is that I really like using JavaScript - I'm genuinely surprised!
It was only a few years ago when I finally rid myself of ActionScript 2 and I was ecstatic about that. The ActionScript 3 way of doing things seemed to make a lot of sense to me and I've since written tens of thousands of lines of the strictly typed, compiler checked goddess. But is she a false idol.
At present, Adobe is recruiting people to the Flash platform via the new child, Flex. Up until people started throwing around the term RIA, the Flash user base was primarily made up of creatives & devigners who made some pretty amazing websites (lets forget about skip-intros for now) with what they had. Now the Flash base is increasing filling up with Java and C# types who expect a certain level of features, complexity and checks - Adobe continues to encourage it and the old base seems to be increasingly disillusioned.
The overwhelming message is that ActionScript 3 is necessary and better than all it's predecessors. Now a big part of me believes this, in-fact I'd say it was pretty accurate. But I can't help but feel that it's hurting the essence of the platform and the web in general. It's almost as if ActionScript (and some of it's base) has a kind of inferiority complex and must be more like its mature peers in-order to be accepted. In-fact the power of ActionScript (and some of it's base) was always in it's simplicity - "less is more" so they say. And this is exactly what I've found out over the past few months with JavaScript.
The expressive power of JavaScript is wonderful. And so is the expressive power of AS3 once you take away the strict typing, package name-spacing, verbose eventing and the classical-OO pretense because you're left with the stuff you care about, the stuff that actually gets things done. More importantly you're left with something that looks just like JavaScript, no surprises there seen as they are ECMAScript cousins. Well maybe you could say AS3 is the bastard child now that ECMAScript 4 has been abandoned (- I think this post can stand without doing into depth on this subject).
But isn't the big benefit of ActionScript 3 with strict typing the speed? - surly this is key to Flash success. This statement is utterly incorrect. First and foremost, the majority of Flash's execution lies in the rendering of the stage. If AS3 is only doing [box.x+=1] then render is doing a hell of a lot more updating pixels on the screen. It is OK if your AS3 code is convoluted because the renderer will always be your bottleneck. The other mis-conception is that strict-typing improves execution speed. The evidence is probably running right in your face: most modern browser JavaScript engines are in-fact faster than Tamerin (the AS3 virtual machine). Additionally, Joa Ebert has really thrown egg on Adobes face this past year by showing the community just how unoptimized the AS3 compiler is.
So what was good about the introduction of ActionScript 3. Well, for me I think the bigger issue was at the API level. I think people enjoy AS3 over AS1 and AS2 because of a cleaner API into the platform and the finer-grain/cleaner control you get over the display-list. If you were to put put ActionScript 3 into the browser as a JavaScript replacement, you'd still end up with the problems of having to work with the awful HTML DOM. The language in Flash was never the issue.
Adobe Flash is increasingly being squeezed by it's competitors who all want a bite from the RIA apple. Adobe can no longer afford to ship a niche language. Especially if they expect to draw in fresh blood into platform. A move to JavaScript (ECMAScript 5) would seem like the sensible option for the future of Flash. A grander alternative option would be a .NET type approach, enable many commonly used scripting languages (JS, Python, Ruby, Lua, etc) to becoming first class Flash languages, but maybe that's too over the top. Simply moving to JavaScript will bring renewed expressiveness to the platform and once again it'll be approachable by new talent, who at the end of the day, will make or break a platform.
I'll end this with an example of expressiveness. Both these snippiest do the same thing: load an external JPEG and add it to the stage once loaded. I understand that you could encapsulate the JavaScript approach in AS3 - The point is that you shouldn't have to.
EDIT: People have commented heavily about the following snippets. Please don't take them as the overriding message of this article. The main message of this article is about AS3 being a niche language with too many constraints - JS could easily take it's place.
EDIT2: I've started an open source project called $flash, hosted github, with the aim of creating a whole AS3 lib based on the JavaScript snip below.
// JavaScript
flash.load("lolcat.jpg", {
success: function(bitmap) {
gallery.addChild(bitmap);
},
error: function(msg) {
trace("no lolcats found");
}
});
// ActionScript 3
import flash.events.IOErrorEvent;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
var url:URLRequest = new URLRequest("lolcat.jpg")
var loader:Loader = new Loader()
addListeners();
loader.load(url);
private function addListeners():void {
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeEvent)
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
private function removeListeners():void {
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeEvent)
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
private function completeEvent(event:Event):void {
removeListeners();
gallery.addChild(loader);
}
private function ioErrorHandler(event:IOErrorEvent):void {
removeListeners();
trace("no lolcats found");
}
Posted Sun Jan 10 2010 15:10:15 | Comments | Post a Comment
Coming Soon
Coming Soon

