Astro (FP10) : Typed Arrays And…More?
I just got word from some people over in Brighton (at Flash On The Beach of course) that Adobe announced support for typed arrays in Astro (Flash Player 10). Yes! I'm pumped about that one. Though it was already public knowledge (see page 13 in the ECMAScript 4 Overview) that this was on it's way to ActionScript in the years to come, I am surprised that they are slipping this into AS3 (rather than AS4). So, how are typed arrays going to work in AS3?
-
// Creates a new array in which all elements must be of type String.
-
new [String]("I am string #1.", "I am string #2.", "I am string #3.");
-
-
// Same operation as above, but different notation.
-
["I am string #1.", "I am string #2.", "I am string #3."]:[String]
Cool right? It gets even better - if Adobe is slipping typed arrays into Astro, what else are they planning on adding to AS3 before making the move to AS4? Here are some previews of what MAY be heading our way (according to the latest draft of ECMAScript 4).
Record Types
Record types are basically property types for generic Objects. Where as with an array you define the type of elements, with a record type you define virtual properties for an Object. That probably doesn't make much sense, so just take a look:
-
// Creates a new generic Object with defined 'x', 'y', and 'z' properties, each of type Number.
-
{x:153, y:62.38, z:100}:{x:Number, y:Number, z:Number}
-
-
// Taking it one step further, you can define the type for use throughout your code.
-
type Point3D = {x:Number, y:Number, z:Number}
-
-
// With the type defined (above), you can use it like so.
-
var objPoint:Object = new Point3D();
-
objPoint.x = 153;
-
objPoint.y = 62.38;
-
objPoint.z = 100;
You're pumped right? But wait, there's more...
The 'like' Operator
The 'like' operator will compare two types to see if they have anything in common. For instance:
-
// Returns 'true' because they both have 'x' and 'y' properties (among other reasons).
-
someMovieClip like someSprite
Ok, so that one is a no brainer. However, the power of 'like' is that the two objects being compared do not need to share the same base classes or implement the same interfaces. In other words:
-
// Returns 'true' because both objects have 'x' and 'y' properties.
-
someMovieClip like somePoint
That's good stuff and will certainly be useful. Ok, how about one more?
Union Types
Union types allow you to specify more than one acceptable type for an object.
-
// Anything typed as Disaster will accept a value that is a Number or String.
-
type Disaster = (Number, String)
Pretty cool, but I can already see this one being abused.
So anyway, there are some other gems in there as well, but these were the ones that grabbed my attention the most at first glance. Returning to the point of this entire post - will any of these make their way into AS3 next year or will we be waiting *patiently* for AS4?
3 Comments so far
Leave a reply

This is all pretty neat.
I assume that typing Arrays will make them more efficient, and not just more debuggable?
And what's the difference under the hood between an Object of a certain record type and an instance of a dynamic class with the same properties made public?
You have a typo with the last example. You use "exceptable" and "except" when I think you mean "acceptable" and "accept". For a second I thought the example had something to do with throwing exceptions
Really good blog, by the way. I've managed to pick up some great tips.
Wow, good catch - thank you. Fixed!