ActionScript 3 Syntax preview

Posted October 11, 2005 12:47 pm
Filed under: ActionScript, Articles by Paul, AS3, Flash, Opinions

Update: Alas, I knew this would be short-lived in value when I posted it. =) Now that ActionScript 3 information has been released by Macromedia, you’ll find these links to ActionScript 3 language descriptions and differences from AS2 more useful than this preview based on the ECMAScript proposal.

I have to admit, since I first heard details about ActionScript 3, combined with the details of Flex Builder 2 (finally Flex the way I wish it was from v.1) I have been jumpy with excitement to tell people about what’s coming: coworkers, users’ group members, and even my wife has gotten an earful. I definitely consider this to be the best thing to happen yet in ActionScript development. (Maybe I should have applied for that Flex Technical Evangelist position, since that’s what I find myself wanting to do anyway!)

So, being unable to wait I dug up the ECMAScript (ECMA-262) 4th edition proposal and combed through it to find out what I could about what’s coming in ActionScript 3. Obviously Macromedia can choose what things to implement or not implement, but they have said (I’m paraphrasing here) that their goal is to be as close to the spec as they can, even the target implementation of the spec. So I think by looking at the spec we can get a pretty good idea at least from the syntax point of view what ActionScript 3 will be like. Of course, the object model is another story — for that we’ll just have to wait to see what Macromedia gives us, and what we as a developer community do with it!

So here’s my summary of the things in the ECMAScript 4th edition proposal which are not included in ActionScript 2. If you are a Macromedia employee, feel free to skip to the end to read other things that I would like to see implemented in addition to what’s in the spec.

Note: in addition to the things included here, Macromedia has publicly stated that AS3 will also support DOM Level 3 events and E4X, which are different specs (E4X is specifically an extension to ECMAScript).

Disclaimer: This is obviously just my interpretation of the ECMAScript spec; it is very possible that I missed or misinterpreted something, so this information may not be correct. In addition, Macromedia has the option of choosing to implement or not implement portions of the spec at their pleasure. Having said that, if you believe a correction is in order, please leave a comment or contact me.

Keywords

Operators

Scope

The following statements now have their own local scope:

Note: a variable will be "hoisted" (it will follow the scope rules of ECMAScript 3/AS2) when all of the following are true: it is defined in a var statement; the definition doesn’t specify a type; it has no attributes except true; the scope it would be hoisted into is not a class; Strict mode is not being used.

Strict mode

This is a more strict compile-time type checking mode. The following conditions are imposed by Strict mode:

Attributes (modifiers)

Variables are public final by default; methods are public virtual by default.

Variables

Method (function) parameters

Classes

Packages

Namespaces

This provides a mechanism to define certain portions of a code file — for example, certain methods of a class — as belonging to one or more namespaces. The use case presented in the spec is to provide a mechanism for creating multiple versions of code in a single file. You could define multiple versions of a method or property, or add new methods and flag them as only belonging to a certain version. Other code which refers to that code can specify which namespace (i.e. which version) of the code it is defined to use, and only the parts of the code which are flagged as belonging to that version (namespace) will be compiled.

I can see how this would be useful for the "importing other authors’ code from a url" situation — if the author updates the code, he/she can specify versions in the same file, and as long as your code points to the version it was created to work with, your code will never break. For ActionScript I don’t know if this is as useful — although I suppose this would allow authors (e.g. Macromedia) to create new versions of classes and still provide a single source file, and would avert the need for separate classpath folders like Macromedia had to do with Flash 8.

Predefined types

* Types marked with an asterisk were defined in ECMAScript 3 but not included in ActionScript 2

There is no longer a distinction between objects and primitive types (all types are objects).

String(), Integer(), Number() are now explicit coercions rather than type conversion functions.

Machine types

These are types defined in the spec, but their names are not reserved words and can be used as identifiers.

Numeric literal suffixes: To specify a literal number of certain types, you need to add a suffix to the number (e.g. var x:long = 25L;). The suffixes are l or L for long; ul, uL, Ul, or UL for ulong; f or F for float.

Things I would like to see, which aren’t in the spec

Macromedia, please take note! You said you wanted to get developer feedback on the direction of ActionScript 3; well, here’s my first feedback:

Things I wish were added, but aren’t (at least, not in the standard)

Things included in AS2 but not in ECMAScript 4th edition

I expect Macromedia will keep these things around in ActionScript 3, and hopefully even add a few more nice things too!

You can leave a comment, or trackback from your own site.

Articles by Type

Articles by Topic

Random Reading

Currently...

Adobe MAX 2011 Speaker H. Paul Robertson: Adobe Community Professional

Subscribe