ActionScript 3.0 overview(2)

Language features

ActionScript 3.0 brings the core language aspects of ActionScript 2.0 into compliance with the ECMAScript standard and introduces some areas of new or enhanced functionality. All of these features are discussed in comprehensive detail in the ActionScript 3.0 Language Reference, available in beta version on Adobe Labs.

Following is a high-level summary of the developer benefits and usage of some of the new features.

Runtime exceptions

In ActionScript 2.0, many runtime errors would fail in a graceful but silent fashion. This ensured that Flash Player would not display some inexplicable dialog box, which JavaScript did in early web browsers. On the other hand, this lack of error reporting made it more challenging to debug ActionScript programs.

ActionScript 3.0 introduces a variety of runtime exceptions for common error conditions, improving the debugging experience and enabling applications that handle errors robustly. Runtime errors can provide stack traces annotated with source file and line number information, helping to pinpoint errors quickly.

Runtime types

In ActionScript 2.0, type annotations were primarily an aid for developers; at runtime, all values were dynamically typed.

In ActionScript 3.0, type information is preserved at runtime and utilized for a number of purposes. Flash Player performs runtime type checking, improving the system's type safety. Type information is also used to represent variables in native machine representations, improving performance and reducing memory usage.

Sealed classes

ActionScript 3.0 introduces the concept of a sealed class. A sealed class possesses only the fixed set of properties and methods that were defined at compile-time; additional properties and methods cannot be added. This makes stricter compile-time checking possible, resulting in more robust programs. It also improves memory usage by not requiring an internal hash table for each object instance. Dynamic classes are also possible using the dynamic keyword.

Method closures

Event handling is simplified in ActionScript 3.0 thanks to method closures, which provide built-in event delegation. In ActionScript 2.0, a closure would not remember what object instance it was extracted from, leading to unexpected behavior when the closure was invoked. The mx.utils.Delegate class was a popular workaround; to use it, you would write code as follows:

myButton.addEventListener("click", Delegate.create(this, someMethod)); 
Delegate.create(this, someMethod)
		  

This class is no longer needed because in ActionScript 3.0, a method closure will be generated when someMethod is referenced. The method closure will automatically remember its original object instance. Now, one can simply write:

myButton.addEventListener("click", someMethod);
          

ECMAScript for XML (E4X)

ActionScript 3.0 features a full implementation of ECMAScript for XML (E4X), recently standardized as ECMA-357. E4X offers a natural, fluent set of language constructs for manipulating XML. Unlike traditional XML parsing APIs, E4X makes XML feel like a native data type of the language. E4X streamlines the development of applications that manipulate XML by drastically reducing the amount of code needed.

Read more about the E4X specification (PDF, 1.8 MB)

Regular expressions

ActionScript 3.0 includes native support for regular expressions so you can quickly search for and manipulate strings. ActionScript 3.0 implements the regular expressions defined in the ECMAScript Language Specification (ECMA-262).

Namespaces

Namespaces are an innovative new mechanism for controlling visibility of declarations. Similar to the traditional access specifiers used to control visibility of declarations (public, private, protected), namespaces are essentially custom access specifiers, which can have names of your choosing. The Flex framework, for example, uses an mx_internal namespace for its internal data. Namespaces are outfitted with a Universal Resource Identifier (URI) to avoid collisions, and are also used to represent XML namespaces when working with E4X.

New primitive types

ActionScript 2.0 had a single numeric type, Number, a double-precision floating point number. One welcome addition to ActionScript 3.0 is the new int type—a 32-bit signed integer that lets ActionScript code take advantage of the fast integer math capabilities of the CPU. The int type is great for loop counters and almost anywhere a decimal point isn't needed. Another new type is uint, an unsigned 32-bit integer type similar to int.

 

Flash Player API features

The Flash Player API is a set of classes and functions that expose the capabilities of Flash Player to the ActionScript language. This functionality is the bridge between the ActionScript core language and the rest of the platform. It is the source of much of the power available to Flash applications and is a very important complement to the core language. Although there isn't space here to cover the APIs in detail, here is a short list of some of the new and interesting functionality available to developers:

DOM3 event model

The event model provides a standard way of generating and handling event messages so that objects within applications can interact and communicate, maintaining state and responding to change. Patterned after the W3C DOM3 Events specification, this model provides a clearer and more efficient mechanism than the event systems available in previous versions of ActionScript. The Flex application framework uses the same event model as the Flash Player API, so the event system is unified across the platform from top to bottom.

Display List API

The Display List API consists of a revamped set of classes for working with the visual primitives in Flash.

The new Sprite class is a lightweight building block, similar to MovieClip but more appropriate as a base class for UI components. The new Shape class represents raw vector shapes. These classes can be instantiated naturally with the new operator and can be dynamically re-parented at any time.

There is no longer any need to assign depth numbers to display list objects. Depth management is now automatic and built into Flash Player. New methods are provided for specifying and managing the z-order of objects.

Where to go from here

This ActionScript 3.0 overview outlines only a few of the exciting APIs and language features you'll discover as you learn more about ActionScript 3.0. Programming ActionScript 3.0 on LiveDocs (or as PDF) is a good place to start for information on how to implement programming concepts in ActionScript, and the ActionScript 3.0 Language Reference will be the definitive source for complete information about the core language and the Flash Player API. Also, if you're already familiar with ActionScript 1.0 or 2.0, check out Tips for Learning ActionScript 3.0.

The Flash Player team is thrilled to be able to deliver a preview of the language, its new capabilities, and improved performance to the community through Adobe Labs. You will be able to explore ActionScript 3.0 to see where we are taking the language through Flex Builder 2, the Flex framework, Flex Data Services 2, and Flash Player 9. We hope you are as excited as we are about the future of the platform, and look forward to the feedback you will provide us through Adobe Labs.

About the authors

Gary Grossman is a software architect who works on Flash Player at Adobe. Gary joined the Flash team at Macromedia in 1998 and has worked on every release of Flash since Flash 4 in a variety of capacities, from engineering to management. He has had the pleasure of working alongside such Flash luminaries as Jonathan Gay, the original inventor and author of Flash. Gary was the primary developer on the ActionScript programming language in Flash 4, Flash 5, and Flash MX. He continues to participate actively in the evolution of the ActionScript programming language. Gary lives and works in San Francisco, California.

Emmy Huang is Senior Product Manager for Flash Player. Her experience includes working in engineering and product management on a range of digital entertainment technologies at Sony Pictures Digital, Liberate Technologies, and Intel. She briefly flirted with the idea of switching to another industry while working towards her MBA at UCLA but decided that working in software was way more fun than selling bleach.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值