Newsletter sign-up
View all newsletters

Sign up for our Enterprise Java Newsletter

Enterprise Java

ActionScript for Java developers, Part 1

Learn how ActionScript 3 differs, and doesn't, from Java

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Hybridizing Java sounds sexy but learning ActionScript ... not so much. In this two-part article, Chet Haase gets you started toward the Great Migration, with a Java developer's perspective on what's different about ActionScript 3 and its flashy, scripty syntax. In Part 1: An overview of ActionScript 3 and how its basic syntax and class behavior differs from Java's. In Part 2: An advanced look at how ActionScript handles properties, dynamic behavior, and functions. Level: Intermediate

About a year ago, I packed up my things and moved dimensions. I went from programming full-time in Java to working on the Flex team at Adobe, where I now program in ActionScript 3. I was looking forward to the change because I think that an occasional radical shakeup usually works out well, unless you're talking about babies or champagne bottles.

But I wasn't quite so sure about the language barrier.

I'm not an expert in programming languages -- at all. I'm just a graphics geek who learns enough about languages to get the job done. And I figure we can all do what we need to in any language as long as we understand the rules and constraints. But I did come to the new platform with a just a tad of supercilious Java bias, thinking "Isn't ActionScript that toy language that designers use for sprinkling code into animations in the Flash authoring tool?" I mean, any language with script in 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 JavaOne 2008, "The Jay-va.") Right?

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 (see Figure 1). 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.

A similar class written in Java and ActionScript 3.

Figure 1. A similar class written in Java and ActionScript 3. Differences are shown in bold. (Click to enlarge.)

So while I'm not a language expert (I'll keep emphasizing that, to make sure that nobody sends me questions about lambda expressions or BNF grammars or anything else I can't answer), I thought that it would be useful to take a step back from both languages and compare them from this programmer's point of view. I'll compare various aspects of the languages to see what ActionScript 3 looks like to a Java developer. In so doing, I hope to help you avoid some of the pitfalls and misconceptions I encountered in my own migration to the Flex SDK.

On the delicate art of comparison

The goal of this article is not to depict one language as better than the other. I think that all languages have their place (I could throw in an unkind jibe here about some older or untrendy languages, but I will pretend that I am above that). Instead, I just want to examine things that are similar and different about Java and ActionScript 3, and what these characteristics contribute to how we use each language.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (6)
Login
Forgot your account info?

Java FX is advanced asBy Anonymous on March 15, 2010, 2:08 pmJava FX is advanced as compare to java and does help to develop rich internet applications as well as next generation web applications. Runtime environments, widgets,...

Reply | Read entire comment

JavaFX- I need to give it aBy Jordan2009 on September 28, 2009, 10:13 pmJavaFX- I need to give it a try. I have heard about it from other sites as well. It seems a good offer for the users. Puppies for sale

Reply | Read entire comment

CastingBy Anonymous on February 20, 2009, 10:13 amOne thing it took me a while to realize is that there is a difference between the two methods of casting: var g:int = int(f); will throw an exception if f is not...

Reply | Read entire comment

Comparing JavaFX Script to JavaBy Athen on February 19, 2009, 8:22 pmHi, That is a good topic, but for another article. Jeff Friesen discusses differences between JavaFX Script and Java code in his article "Jump into JavaFX Script."...

Reply | Read entire comment

Re: what about JavaFXBy Anonymous on February 19, 2009, 1:22 pmCould be an interesting piece, but it seemed more useful to compare against a language with a larger user base. Most developers (especially on the JavaWorld site)...

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • "Java EE and Flex: A compelling combination" (Dustin Marx, JavaWorld, January and February 2009) introduces techniques for integrating Flex clients with a Java back end.
  • "Client-side Java's evolutionary leap" (Jeff Friesen, JavaWorld, January 2009) looks back on 2008 as a momentous year for Java desktop and RIA technologies, with commentary from many leaders and innovators in client-side development.
  • "The ABCs of RIA" (Paul Krill, Infoworld, August 2007) is a survey of tools and frameworks used in rich Internet application development.
  • ActionScript Developer Center is the Adobe developer site for the language.
  • The Flex SDK Open Source site is the open source repository for the Flex libraries. You can download the latest release of Flex and build applications with it, or download the source code and build Flex from scratch. Also check out learning resources such as the Flex Developer Center site and Flex.org.
  • Flex Builder is Adobe's IDE for building Flex applications. The Flex SDK is free to use, but tools can make development easier.
  • The Flash Development Center provides resources for developers writing programs for the Flash platform, which can be done either with Flex, or by using the Flash APIs directly, or with the Flash authoring tool.
  • Filthy Rich Clients (Chet Haase and Romain Guy; Addison-Wesley/Sun Microsystems Press, August 2007) is a definitive guide to client-side development in Java.
  • Chet Haase regularly posts graphics, animation, and tutorial articles and videos to his technical blog Codedependent, and irregularly posts comedy writings to his non-technical blog Enough About You.

More from JavaWorld