Hybridizing Java sounds sexy but learning ActionScript... not so much. In this two-part article, Chet Haase gets you startedtoward the Great Migration, with a Java developer's perspective onwhat's different about ActionScript 3 and its flashy, scripty syntax.In Part 1: An overview of ActionScript 3 and how its basic syntax andclass behavior differs from Java's. In Part 2: An advanced look at howActionScript handles properties, dynamic behavior, and functions. Level: Intermediate
Abouta year ago, I packed up my things and moved dimensions. I went fromprogramming full-time in Java to working on the Flex team at Adobe,where I now program in ActionScript 3. I was looking forward to thechange because I think that an occasional radical shakeup usually worksout well, unless you're talking about babies or champagne bottles.
But I wasn't quite so sure about the language barrier.
I'mnot an expert in programming languages -- at all. I'm just a graphicsgeek who learns enough about languages to get the job done. And Ifigure we can all do what we need to in any language as long as weunderstand the rules and constraints. But I did come to the newplatform with a just a tad of supercilious Java bias, thinking "Isn'tActionScript that toy language that designers use for sprinkling codeinto animations in the Flash authoring tool?" I mean, any language withscriptin its name is obviously going to be a step down from the mighty Java.(Or, as Neil Young put it in his surreal cameo appearance at JavaOne2008, "The Jay-va.") Right?
Iwas therefore pleasantly surprised to find that ActionScript 3 isactually quite a powerful language, and was syntactically similar toJava in many ways (see Figure 1). Yes, it's a scripting language withdynamic behavior and less type strictness than we have come to expectfrom Java. But it also has a lot of similar type behavior,object-oriented structure, and package/class/method/field organizationthat makes it look, well, almost Java-like.
[img=350,270]http://www.javaworld.com/javaworld/jw-02-2009/images/actionscript1-fig1_thumb.gif[/img] Figure 1. A similar class written in Java and ActionScript 3. Differences are shown in bold. (Click to enlarge.) Sowhile I'm not a language expert (I'll keep emphasizing that, to makesure that nobody sends me questions about lambda expressions or BNFgrammars or anything else I can't answer), I thought that it would beuseful to take a step back from both languages and compare them fromthis programmer's point of view. I'll compare various aspects of thelanguages to see what ActionScript 3 looks like to a Java developer. Inso doing, I hope to help you avoid some of the pitfalls andmisconceptions I encountered in my own migration to the Flex SDK.
On the delicate art of comparison Thegoal of this article is not to depict one language as better than theother. I think that all languages have their place (I could throw in anunkind jibe here about some older or untrendy languages, but I willpretend that I am above that). Instead, I just want to examine thingsthat are similar and different about Java and ActionScript 3, and whatthese characteristics contribute to how we use each language.