ActionScript != JavaScript

If you were planning on implementing a tool or SDK for creating HTML pages with JavaScript from pre-existing Flex or Flash projects with ActionScript your tool would need to support two types of features:

  1. Language features
  2. Runtime features.

Language features are features like classes and inheritance while runtime features refer to Flash Runtime and browser features like Sprite and Element.

In this post about cross-compiling ActionScript to JavaScript I would like to focus on language differences between ActionScript and JavaScript. I’ll talk about runtime features in separate posts later.

Ideally your cross-compiler should transform every expression found in the source language into equivalent expressions of the target language. The main goal is preserving the internal consistency of the source code in the generated code of the target language. Fortunately ActionScript and JavaScript have a lot of overlapping language features. But there are also some ActionScript languages features that are either different, or missing in JavaScript. At the syntax level you’ll notice that ActionScript added these keywords:

as, class, const, extends, implements, import, internal,
is, native, package, private, protected, public, super,
use, void, get, set, namespace, include, dynamic, final,
override, static.

Language differences between ActionScript and JavaScript can also grouped into missing features and features, that seem to be the same but are different.

Missing features in JavaScript:

Features that are different:

  • meaning of “this” in methods
  • core class APIs: Error, Date.

In the following posts I am going through that list and will explain how those features could be transformed to equivalent (and sometimes unfortunately only almost equivalent) JavaScript features.

Please keep in mind that I am not claiming that my proposed transformation are the best solutions. I am just saying that my transformations are one way of getting JavaScript code that is functionally equivalent to the ActionScript code it originated from. Also, I would like to emphasize that my code examples might or might not match what FalconJS generates. I don’t want to give the impression that my examples are FalconJS solutions.

Finally, the postings on this site are my own and don’t necessarily represent the position, views or opinions of Adobe. My code examples are presented on an “as-is” basis, without warranties or conditions of any kind, and are primarily intended for illustration purposes.

Now that we got that out of the way let’s move on to more fun stuff like Classes, Inheritance, and Interfaces!

One Response to ActionScript != JavaScript

  1. ZJCQoo says:

    Hi. I’m very interested in your discovery. In fact, I also do the same research as you, but met a lot of difficulties in the work.

    this is an example that try to run javascript in actionscript environment: