Skip to content
Published March 26, 2015

It’s been quite awhile since my last post, so I figured it was time for something big. Today I’d like to introduce to you AS3JS!

AS3JS Logo
http://as3js.org

 

This is a little project I’ve been developing on the side in an attempt to make HTML5 development a little easier. It’s a command-line tool built with Node.js (and leveraging my previous library- ImportJS) that can convert AS3 code files into valid JavaScript. While it’s not perfect (hence why I’m calling it “dumb” for the time being), it’s definitely something I’ve found extremely powerful in some some large JavaScript apps I’m working on right now. This article will go over some of it’s features, as well as why I created it. (You’ll have to excuse me if I rant a bit, I wanted to spare the Github documentation all the TL;DR )

Example AS3JS Project

In case you don’t feel like reading all of this, let me start off by linking you to a cool little project I built in AS3 that runs in pure JavaScript. I even exported a Flash version as well just for kicks.

https://github.com/Cleod9/ElevatorJS

I certainly hope the demo convinces you to read this rest of this article 😉

Why ActionScript?

To be frank, I’ve grown quite tired of two things:

Why can’t we make JavaScript easier without adding so much baggage to the language? I say let’s take a step back from ES6 for a second and examine another overlooked language with a ton of potential on the web. For those of you already familiar with ActionScript, I’m sure you’re already well aware of some of its awesome features:

  • Typed variables
  • Classes
  • Package import system
  • Encapsulation
  • Much less “this” everywhere

Why not use these same exact features on the web? I don’t mean to put down ES6 and some of it’s strong points, but ES6 is still evolving as we speak while ActionScript has been a stable development language for years. It’s only recently that we started seeing attempts to convert AS3 to JS, and I think at the very least we could learn from such a language. TypeScript is a prime example of positive AS3 influence on the JavaScript language, although it itself is starting to conform to ES6 standards.

But ActionScript is Flash right? Flash is evil/stupid/dead/obsolete!

Now calm down for a second and listen to yourself. ActionScript is not Flash, it’s a coding language. The language happens to be a superset of ECMAScript, and as such valid JavaScript syntax is valid in ActionScript. AS3JS is not about Flash, it’s about ActionScript. If you don’t want to assign types to all your variables you don’t have to! But the fact of the matter is that you can, and in doing so you can get some pretty powerful features from your IDE like code hints, auto-completion, and automated refactoring. Not to mention how easy ActionScript’s package system is to use.

Do you have a problem with JS/ES6 or something?

The short answer is yes. But for me it’s all about redundant code. The number one thing that bothers me about JavaScript is how often you have to write out the word “this”, when inside class-like structures there is technically enough information to infer where “this” needs to be used. In ActionScript the “this” is implicit (i.e. optional) in class files, and there are very few situations where you actually need it. As such, AS3JS will automatically take care of prepending “this” where it’s needed in its JS output.

Now don’t get me wrong, JavaScript is my favorite language next to ActionScript. My favorite part about JS is its simplicity, and the fact that it does very little for you out of the box. It pains me to see new constructs are being added to the next generation of JS (ES6) that, while admittedly save keystrokes, slowly eat away at the simplicity of such a dynamic and expressive language. I would rather encourage developers to get comfortable with vanilla JavaScript and not rely so much on fancy new symbols and keywords that require keeping up with a constantly evolving documentation.

But what about TypeScript / CoffeeScript / ES6 / FlexJS / Jangaroo / Dart etc.?

Well since you asked, I’ll gladly comment on each of them:

  • TypeScript – To be honest, if I didn’t have the ability to write AS3JS (or if I didn’t know what AS3 was) I probably would get into TypeScript. But I’ve been developing in ActionScript for a decade and TypeScript looks eerily similar, so I thought “wouldn’t it be cool to use the language I have a preference for on the web?”. Also, TypeScript seems to be adopting many concepts from the ES6 spec, and it’s gotten the point where the two look virtually identical (minus the type safety). If that’s the case, I’d choose ES6 over TypeScript if presented with no other options.
  • ES6 – ECMAScript 6 is the latest version in the JavaScript spec. While it attempts to solve many “problems” in the JavaScript language, to me a lot of it just doesn’t look like JavaScript to me anymore and it feels like a lot of concepts from other languages being crammed into one. In other words, it’s as if everyone wants to satisfy audiences that come from completely different programming backgrounds. Things such as arrow functions, generators, destructuring (ugh, yes it’s less code but boy is it confusing), and the like, are great features for experienced developers but can become a serious obstacle for newbies. In addition, a lot of these constructs that were added can already be built without ES6, so why not standardize some JS libraries instead of building these things into the language just to save a few characters of text?
  • CoffeeScript – Let me just say that I think the syntax of CoffeeScript is the main turn off for many people, and as with TypeScript it has adopted many concepts from ES6. I personally find the code takes longer to comprehend at a glance without the curly braces, and the symbols it uses to save a few bytes of text just isn’t worth it to me. You could argue it just takes some getting used to, but you can say that just about any language. In a higher level coding language like JS I would prefer to code in a format that resembles its output form a little more.
  • Dart – Since Dart is newer than most of the other languages I listed above, the only argument that comes to mind for me is that this is just yet another language to learn. I think developers could benefit from mastering existing languages before adopting new languages that they are based on.
  • FlexJS – While it’s technically an AS3->JS converter there are several issues with FlexJS, the biggest of which is that it’s designed around the Flex SDK and is still in alpha. Flex also implies the Flash Player, and I think this is a turn off to many JavaScript developers. Why not let the AS3 language work independently from the Flash/Flex platform?
  • Jangaroo – This one is another AS3->JS compiler. Not only have most people not even heard of this, but I personally think the compilation process is overly complex since it relies on Java. The project also does not seem to be maintained all that well. I think Node.js is a much more suitable platform for converting any language to JavaScript since JS devs can jump right into it, and the JS community can even chip in themselves.

Final Thoughts

So in conclusion, I think it’s important we consider the potential of ActionScript as a native web development language. Even if my AS3JS tool doesn’t become widely used, I would find comfort if members of the JavaScript community (and Adobe) would take ActionScript seriously as a language for the web. As we slowly move away from browser plugins, let’s make sure the alternative moves us forward instead of backward.

6 Comments

  1. Greg McLeod,

    Thanks for great article. As you mention Adobe should taken initiative for making Actionscript for web and independent of flash platform. It is really great language and so much easy to manage even enterprise projects.

    Highly appreciate your view and hopes this will happen in future.

    Best Regards,
    Ravichandran
    Flex Developer

    • Greg McLeod Greg McLeod

      I appreciate the comments! I very much agree, AS3 thrives in enterprise projects. JavaScript has only recently started being used for projects of such a scale, so I believe there is plenty of time for AS3 to hop in the scene if ever given the green light by Adobe.

  2. Beautiful is an understatement. Creating custom UI widgets in Actionscript is a pleasure compared to any other language I’ve ever used. I suspect most developers don’t understand its power because they’ve never had to do anything even remotely related to design. And that makes me sad because Actionscript deserves a place in the toolkit of any working programmer out there.

    • Greg McLeod Greg McLeod

      Thanks for the comments! It’s nice to hear from a fellow ActionScript fan 🙂

      I think you’re right, quite frankly it’s likely that most web developers in particular have just never worked in an ecosystem like Flash where the coding and design are intertwined so seamlessly. Because of this I think we have a long way to go with UI tooling for web development. There is a lot we can learn from ActionScript/Flash that I’d love to see applied to web dev one day!

  3. Hells, yes, mate. It’s about time someone did this. I was just waiting to see when it would happen.

    I’m interested to hear your thoughts on Haxe.

    • Greg McLeod Greg McLeod

      I don’t have all that much experience with Haxe, but I do like the idea behind it and even considered doing a large scale cross-platform game with it once. My main issue with Haxe at the moment is that I don’t yet feel comfortable with its stability/optimization at a scale. My worst nightmare would be to commit to a Haxe project and find out 6 months into development that I can’t support a particular platform I planned on due to stability/performance issues. I love the idea behind Haxe in that it is one language for development in just about any platform, but when you’re working in environments that are a bit dated I’m not sure I trust that Haxe would perform well. In my case for web development, I’m having a hard enough time as it is optimizing JavaScript in low-resource environments. So to throw Haxe on top of that just isn’t an option.

      Anyway, while I don’t have anything against Haxe it does seem worthy of development on more modern systems. Not to mention I’m pretty interested in OpenFL which looks promising!

Leave a Reply

Your email address will not be published. Required fields are marked *