Typed Arrays - Hurray!
Posted: 22/07/08
I for one am very pleased to see that the typed Array is making a debut in the forthcoming Flash Player 10 release! For those that have been playing heavily with the Flex API, you know it's "kind of" been possible to type an Array using the following meta-data:
[ArrayElementType("Number")]
private var myArray:Array = new Array();
Unfortunately, this code only works when nested inside <mx:Script> blocks in an MXML application; it doesn't work for pure AS3.0 applications. So Flash has been left behind with this one, and it really emphasises that typed Arrays should have been part of the core player.
In the new Flash Player 10 API, the new Vector class brings the ability to strongly type Arrays, and forces errors when invalid types are pushed onto it. It's worth noting that base types must match exactly - attempting to type the Array to an interface or abstract class, then trying to push derived objects will throw errors.
This will be fine:
var v:Vector.< Sprite > = new Vector.< Sprite >();
This will throw an error:
var v:Vector.< DisplayObject > = new Vector.< Sprite >();
I for one can't wait for this feature to be introduced, as it will remove one of the last weaknesses in enforcing strongly-typed OOP in Flash applications.
Flash Player 10 beta and supporting docs
Keywords for this post: Flash Player 10, ActionScript 3, Array, typed, Flex, Flash
Popular categories:
Recent posts:
- Mac OS find files using regex
- ADB device driver won't install
- Eclipse: An error has occurred. See the log file .metadata/.log
- Updated blinkbox iPad app
- Nexus 7 doesn't appear in adb devices list
- Improve the keyboard in the Samsung ICS update
- 403 Forbidden error on Mac web server
- Getting error with manually created NIB?
- Adding/removing items from PATH on Mac
- Presenting at Flash Oxford
- more...
Publications:
Places you'll find me:
Archive:
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023