Flash AS3 new features and changes relative to AS2

Source: Internet
Author: User
Tags class definition inheritance integer new features regular expression relative version variable

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

The

instances that are generated by the class definition are of type Sealed in AS3, whose 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

    The
    • adds a Display API that allows AS3 to control most SimpleButton including Shape, Image, TextField, Sprite, MovieClip, video, loader, DISPL, and so on. Aylist Rendering Unit. 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.
    • adds the DOM event API, where all rendering units on displaylist support a new three-segment event playback mechanism, with Stage as the starting point to broadcast events to target objects (this process is called Capture Phase) and then broadcast The event is reported to the target object (this process is known as Target Phase), and finally to the Bottom-up broadcast event (this process is called bubbling Phase).
    • adds built-in Regular Expressions (regular expression) support to enable 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.
    • adds 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.
    • adds a socket class that allows you to read and write binary data so that the underlying network protocols (such as POP3, SMTP, IMAP, NNTP, and so on) can be parsed through as, allowing Flash Player to connect to mail servers and newsgroups. The
    • adds a Proxy class to replace the Object.__resolve feature in AS2. The
    • adds new support for reflect (reflection), and the related methods are 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







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.