Flash ActionScript 3 new features and changes

Source: Internet
Author: User
Tags class definition inheritance integer md5 hash new features regular expression require

This article describes the new features and changes that ActionScript 3 has in relation to ActionScript 2. And in the last step of the article to teach you how to use Flex Builder to compile and run the first AS3 program.

  Syntax enhancements and changes:

Two concepts of package (package) and namespace (namespace) are introduced. Where package is used to manage class definitions, to prevent naming conflicts, and namespace to control access to property methods.
New built-in type int (32-bit integer), uint (nonnegative 32-bit integer), is used to speed up the integer operation;
NEW * Type identification, used to identify a variable of type uncertainty, usually used when a run-time variable type cannot be determined. In the case of AS2, Object Lai is used as the type of table recognition.
The IS and as two operators are added for type checking. Where is replaces instanceof in AS2 to query the inheritance of class instances, while as is used for type conversions that do not throw errors.
The new in operator queries the properties of an instance or whether there is a property of the specified name in its prototype.
Add a to each statement to iterate through the Array and object instances.
Add a const statement to declare a constant.
New Bound method concept. When a method of an object is paid to another function variable, this function variable points to a Bound method to ensure that the scope of the object's methods remains on the object that declares the method. This is equivalent to the Mx.util.Delegate class in AS2, which is completely built into the language in AS3 and does not require additional write code.
The AS3 method declaration allows you to specify a default value for the parameter (implement optional parameters).
AS3 method If you declare a return value, you must explicitly return it.
A void identifier in AS2 that indicates that the method has no return value and is changed to void in AS3.

  OOP enhancements

An instance generated by a class definition belongs to the Sealed type in AS3, that is, its properties and methods cannot be modified at run time. This part of the property is stored in the AS2 by the class's prototype object, and in AS3 it is not controlled through the concept object storage management called Trait. This approach reduces the time it takes to find the property method through the prototype inheritance chain (all the implementation methods and properties of the parent class are copied directly into the Trait of the corresponding subclass), and on the other hand reduces the memory footprint because you do not have to dynamically create each instance Hashtable to store variables. If you still want to use the dynamic characteristics of a class instance in AS2 at run time, you can declare the class as active.

  Enhancements to the API aspect

New Display API to enable AS3 to control most SimpleButton rendering units including Shape, Image, TextField, Sprite, MovieClip, video, loader, displaylist, and so on 。 This Sprite class can be simply understood as a MovieClip that does not have a timeline, and is suitable for use as a basis for components such as subclasses that do not require the function of the timeline. The new version of the MovieClip is also more than AS2 for the Scene (scene) and label (frame label) program control. In addition, the creation and destruction of rendering units are implemented by means of joint new operators and Addchild/removechild, and old methods like Attachmovie have been discarded, and no further processing of depth values is required.

New DOM event API, all rendering units on displaylist support a new three-segment event playback mechanism, Stage from top to bottom to target objects (this process is called Capture Phase), and then broadcast events to target Object (This process is known as Target Phase), and finally the Bottom-up broadcast event (this process is called bubbling Phase).
The new built-in Regular Expressions (regular expression) support enables AS3 to efficiently create, compare, and modify strings, as well as quickly parse large amounts of text and data to search for, remove, and replace text patterns.
New ECMAScript for XML (e4x) support. E4X is the XML processing syntax built into AS3. XML becomes a built-in type in AS3, and the previous AS2 version XML processing APIs are transferred to the flash.xml.* package to maintain backward compatibility.

The new Socket class, which allows you to read and write binary data, makes it possible to parse the underlying network protocols (such as POP3, SMTP, IMAP, NNTP, and so on) through as, allowing Flash Player to connect to mail servers and newsgroups.

Add the proxy class to replace the Object.__resolve function in AS2.

New support for reflect (reflection), related methods in the flash.util.* package.

  Write the first AS3 program

To compile the AS3, you need to first install Flex Builder 2 (the only IDE that currently supports AS3), from Adobe Labs up and down in the latest version of Flex Builder. Then after the installation succeeds, click the shortcut to start Flex Builder. (as shown in figure I)

Figure one Flex Builder 2 splash screen

Click the New button in the toolbar and select ActionScript Project from the pop-up menu. (as shown in Figure II)

Figure II Creating a new ActionScript Project

Enter HelloWorld as the project name in the pop-up dialog box. Then click Finish to determine. (Figure III)

Figure three Enter project details

Enter the following code in the newly opened helloworld.as file: (Figure IV)

Figure Four Helloworld.as code content

Press Ctrl+s to save the file, and then click the Run button from the toolbar to run the program. (as shown in Figure V)

Figure Five running programs

Ultimately, it works in the browser as shown in Figure VI:

Figure six HelloWorld program run results

  Resources

The Adobe Labs website has the latest introduction to AS3 .
  ActionScript 3.0 Language Specification contains information about the details of the AS3 language specification.
Download Open source AS3 Project source code , including MD5 Hash,unittest,json resolution and many other projects.
See questions and answers about all aspects of AS3 .



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.