Search code examples
javascriptactionscript-3

Can I use JS source as Actionscript and vice versa?


I recently realised that Actionscript and Javascript are both implementations of ECMA script. Now I'm wondering what this means in practice.

I have a Flex application written in Actionscript and I'm looking at porting parts of it to Javascript for use in AJAX apps. I have had virtually no exposure to JS so far (not counting occasional onClick handlers in my HTML), so maybe the question is silly. But can I just take my Actionscript classes and use them in JS code?

Naturally, I can't use any of the Flash Player APIs in JS and no DOM in my Flash movie, this much is obvious. Are there other important libraries on either side that can't be used on the other?


Solution

  • AS3 is an ECMA-script dialect at best. It is an implementation of a ECMA-script draft that has been completely dropped. JS is a subset of AS3. However the ActionScript compiler included in the Flex SDK will complain about any untyped variable or function, so you'll have an awfull lot of warnings when you compile.

    You should definitely have a look at Jangaroo.

    And, as always, my personal advice is for you to slowly migrate (at least the logical parts of your application) to Haxe for obvious reasons. You can use as3tohaxe, to facilitate porting.