AS vs JS GCD - WTF!?

  AS -> ActionScript programming language
  JS -> JavaScript programming language
  vs -> versus
  GCD -> greatest common divisor
  WTF!? -> wtf

translation: Common stuff between ActionScript and JavaScript programming languages.

Both ActionScript and JavaScript are based on ECMA Script standard, so it's inevitably to have same language core. Syntax is almost the same, also object model and many classes like Array, Date, Math and String. Both languages implement same operators and dot syntax, so when you look at the code sometimes you will not be able to see the difference, because in some parts there aren't any.

Take a look at Drawing with JavaScript in HTML5 vs ActionScript 3 in Flash article by @WilliamMalone HTML5 Game developer from Denver, Colorado. Example will walk you through drawing of dynamic content (in this case it's a warning icon) in AS as well as in JS and every step has been done simultaneously which is perfect to notice differences and common things.

JavaScript / ActionScript drawing example

There are also things which are very similar and with similar function, but not the same. In ActionScript there are Local Share Objects and they look like other key-value based datastore, JavaScript "favorite cookies". Also event listeners and event handling is key on both sides if you considering game development and interactivity programming.
This is pretty much how to add new eventListener:

target.addEventListener('click', function() {
    /* actions */ 
}, false);

There are tons of predefined Events in AS and JS and you can create Custom Events if you want.

Browser window event types are: onclick, ondblclick, onmousedown, onmousemove, onmouseover, onmouseout, onmouseup, onkeydown, onkeypress... 

You will probably use canvas as target in your browser, in this way:
canvas.addEventListener("type", function, false);

in which case you use "type" area events like these: click, dblclick, focus, focusin, focusout, keydown, keypress, keyup, mousedown, mouseenter, mousemove, mouseover, mouseup, mousewheel, pause, scroll, touchstart, touchmove ...

Despite many differences between ActionScript and JavaScript there is huge greatest common divisor worth knowing and developers who use both languages can confirm this is great advantage in fast moving web development world.

[to be continued]


Post a Comment


  1. yes, please note that extremely informative comments will be also deleted

    thank you

  2. All very true! There are a bunch of similarities not in the least due to both being ECMA. Another approach is to outline some key differences, the big three that come to mind are:

    1) Flash has strong typing, JavaScript doesn't.
    2) Flash is Compiled so has Early Error detection, JavaScript doesn't.
    3) Flash has legitimate OOP structure, JavaScript doesn't.

    As a programmer these are pretty significant on the list of things to consider.

  3. Thanks for your comment. There are many differences between the two I agree and many posts out there are about them, that's why my intention was to write about similarities among them.


Thanks for sharing your thoughts !