Adobe's ActionScript language has a long history: starting as a scripting language for the Flash authoring tool, it evolved into a full-fledged functional, object-oriented, prototype-based language.
ActionScript is closely modeled on JavaScript: until last year ActionScript was, in fact, an implementation of the next-generation JavaScript specification. That means that a great deal of JavaScript code and libraries work in ActionScript. But ActionScript has a large, and growing set of libraries of its own, all the way from the Flex application-development framework to sophisticated multimedia handling packages.
Implementing both prototype-based objects and classes, which are really syntactic sugar on the prototype-based implementation, modern ActionScript code shares many syntactic similarities with Java as well. In a recent article, Chet Haase, formerly on Sun's Swing team and now an Adobe Flex engineer, demonstrates just how familiar ActionScript would appear to Java developers:
ActionScript 3 came out in 2006 with FlashPlayer 9 and Flex 2 and represented a significant change in the core language. All of the old capabilities and syntax were still there, but more powerful mechanisms familiar to Java developers were introduced, including classes and packages, types, and a new runtime-compiling VM to handle it all... Actually, type annotations, classes, and interfaces were available in ActionScript 2, but only as syntactic sugar to be removed at compile time to accommodate the older ActionScript 1 interpreter. ActionScript 3 integrates these features for real...
[I imagined that] any language with script in its name is obviously going to be a step down from the mighty Java... I was therefore pleasantly surprised to find that ActionScript 3 is actually quite a powerful language, and was syntactically similar to Java in many ways...
Yes, it's a scripting language with dynamic behavior and less type strictness than we have come to expect from Java. But it also has a lot of similar type behavior, object-oriented structure, and package/class/method/field organization that makes it look, well, almost Java-like...
In the article, Haase discusses the concept of "undefined," "null," and "NaN" as types; package declaration syntax; variable scope; annotations and metadata; semicolon inference; type casting; checked and runtime exceptions; generics support; language-based XML support; constructor visibility; and interfaces and properties.
What do you think of ActionScript 3 as a language? How would you compare it to Java from the point of view of expressiveness and developer productivity?
I started programming ActionScript 3.0 in December 2006 coming from Java backend. It was an easy pick-up from the language wise since it is very similar to Java language. Here are some significant differences (to Java) that I encountered when I started coding ActionScript 3.0:-
Type declaration of Variable Instead of doing:- TypeA a = TypeA(); // In Java You will do:- var a:TypeA = new TypeA(); // In AS3 The ':TypeA' is even optional. Function declaration:- public int add(int a, int b) {...} // In Java public function add(a:int, b:int):int {...} // In AS3
Function as first class object Function is a first class object in AS3, you can pass a function around like any other object type. This is particular useful for task like event handling and framework building.
Optional Type Checking You can, declare your class as 'dynamic' class, which you can add additional property to the instance of that particular type like you do in Javascript. For instance:- // Class Declaration public dynamic class TypeA {} // Usage var a:TypeA = new TypeA(); a.special = "Special"; // where the 'special' is not declare in class TypeA.
Event Processing and Data Binding Event processing is baked into AS3. Any custom type object can fire their own custom event and listened by others. This make building loosely-coupled event-driven application extremely easy. Data binding is supported at the Flex framework, provides an easy mechanism to bind your data to UI controls. A single type of data can be bound to different controls without much effort. IMHO, this is the better way to do when programming UI.
I believe the list is longer than this, personally, I have been very happy with AS3 and Flex.
it's hard to compare it since nobody (i guess) is programming in bare as3. everyone is using some adobe tool, so the development is faster and yet the tools are friendly for designers. there are good tools for java too, but they lack the friendliness. maybe would be better to compare javafx vs. as3?
I'm not sure if ActionScript 3 can be called prototype based. ActionScript 2 was for sure. ActionScript 3 is more like 2 languages in parallel really. It contains most of the ActionScript 2 stuff like the prototypes but it also contains a new part, which statically typed. There is no way to fiddle with prototypes in the new part, e.g. changing the base class at runtime or adding properties and methods to a class dynamically. In my day to day job i rarely ever see the prototype stuff beeing used these days.
I am using Actionscript 3 for about a month for designing a simple game. i am a long time java developer. here are my thoughts: - Because of back compatibility, language is cluttered. - built in xml support seems nice, but feels awkward. it may make the language design hard. - The community is still using AS2. there is lack of quality OO developers - libraries. - it looks like java and java script. but with a dynamic smell. - Some obvious stuff is missing (like you cannot remove an arbitrary element easily from an array) - The editor support is very weak. you need to buy expensive Adobe CS4 if you need to deal with design too. the editing support there is terrible. You will miss java IDEs. i know IDEA has support for ActionScript editing but did not try it yet
I think is JavaFX is a serious contender against ActionScript 3 and it is a nicer language IMO. i will make a post once i do the same game with JavaFX.
I have been using pure Java since its beginnings and not too keen on mixing languages. Also I have been working with the automatic generation of vector drawings since my FORTRAN and Turbo Pascal times (1978 and 1984 resp.) There were a lot of graphic languages around - most of them proprietory.
So I was very excited when the XML-based SVG-standard came along around the year 2000 and have been using it since then. There are a lot of XML-handling tools available for free and so I find it easy to programmatically generate and manipulate drawings. Alas, when Adobe discontinued support for its SVG-viewer the situation changed and I started looking at alternatives. I heard all the hype about ActionScript and decided to take a look at it. From what I can see it is an unholy(?) mix between a general-purpose and a "graphical" language.
This reminds me of the dBASE-XX times when Ashton-Tate did the same with its database scripting language. We did a lot of things with it but often ran into problems because of it not beeing a "real" language. (Writing a compiler for it - CLPPER - must have been a nightmare.) Luckily, the SQL standard became popular, and we used FORTRAN, C, C++, Java for programming and SQL for data persistence.
So, what do you use for drawing persistence, when you use ActionScript?
Has anybody any experience with Apache's Batik project? Would this be an alternative for me?
i think i know what you mean, i've been down similar trains of thought if you'll pardon the metaphor.
the problem is that, basically, nothing is as good as Flash. which is pretty depressing in lots of ways. i mean, all the java xml svg stuff is just a load of codswallop now; dead and gone, at least if you want to ship anything to any other user on earth.