C ++ and AS3

Source: Internet
Author: User

ActionScript3 (AS3 for short) and c ++ are both Object-Oriented Programming (OOP) languages with OOP features such as encapsulation, inheritance, and polymorphism. There are many similarities in the syntax between the two. It is not very difficult to learn AS3 after C ++.
However, there is also an essential difference between the two. ActionScript3 is a scripting language, that is, an interpreted language, while C ++ is a compiled language. ActionScript3 is based on ECMAScript4 Netscape Proposal standard and uses AVM2 as its virtual machine. Its main role is to implement interaction, data processing, and many other functions in Flash content and applications. C ++ evolved from the original C language. It has a wide range of applications and is mainly used for large-scale engineering software development. The mainstream three operating systems Windows, Linux, Unix, the kernel is written in C language and sink, and the advanced features of the upper layer are written in C ++. Almost all online games such as World of Warcraft, Baidu search engine, and most of the software we use are written in C ++ (a lot of hardware also uses C ++ ).
AS3 is a "pure" OOP language, while C ++ can only be said to have OOP features, but it also has other features (so it is flexible ). No procedural code is found in AS3, All implementations are implemented in the class and its methods, and even the well-known main function is not found. C ++ retains the process-oriented features. According to the author's opinion in Objective C ++, C ++ mainly consists of four sub-languages: C language, object-oriented language, generic programming language, and C ++ standard template library (STL ).
The above mainly compares the differences between the two in terms of ideology and nature (personal opinion, part of the reference network). The following mainly summarizes some Syntactic differences.
I. ActionScript3 language basics
1. all the built-in types in AS3 are actually objects, and the commonly known "variables" are actually reference names of these objects. Although AS3 also has the value type and reference type, however, the variable of the Value Type actually points to an object that remains unchanged. All value type variables in AS3 are basic types such as int, uint, boolean, Number, and String. The built-in types in C ++ are not objects (because there is no method ).
2. AS3 does not have the pointer concept. All of them are references, and C ++ has pointers. In AS3, we don't have to worry about the generated class object being destroyed in time, because AS3's garbage collection mechanism will help us deal with these things. In C ++, we constantly struggle against memory leaks caused by pointers, Which is why class definitions in C ++ usually contain destructor (~ Fun () but not in as3.
3. In the AS3 program, each executable statement can be followed by a plus sign (";", but added to make the code easier to read), and each statement in C ++ must be followed by a semicolon.
4. AS3 has few basic types, indicating that the integer only has int and uint, indicating that the floating point only has Number, unlike the integers in C ++ which include short, int, long, plus one unsigned in front, float and double in floating point. Each character in the string in AS3 is a Unicode character, but it does not represent a single character variable (such as char, but may be added later ). In C ++, there is the char type, and the strings are represented by char arrays.
5. arrays in AS3 are sparse arrays. They do not support arrays of types, that is, they can store references of different types of objects in the same array. The array in C ++ is a type array, and the types stored in it must be consistent (of course, the base class type pointer can be stored to objects of the derived class type ).
6. in AS3, the default values of variables are many types, especially null, NaN, and undefined. Generally, the default values of the built-in Flash Player class and the object created by the user are null, the default value of undefiened for undefined variables is undefiened. The default type of the Number class is NaN. In C ++, there are not so many types.
7. in AS3, the "=" operator compares the values on both sides of the base metadata type, and for complex data types, compares the references of objects on both sides, even if the values on both sides are the same, however, if the reference is different, the result is false. In C ++, the "=" is mainly used to directly compare the value size (of course, the comparison method can be changed by using the overload operator ). AS3 also has the "=" operator. The difference between it and "=" is that it does not perform any type conversion during comparison, if the type is different, the value is false (except for the value type ). This operator is not available in C ++.
8. type conversion in AS3 mainly uses the as operator, while in C ++, it uses "* _ cast" for type conversion.
9. The delete keyword in AS3 is mainly used to delete the object's dynamic case attributes. The delete keyword in C ++ is to reclaim the dynamically allocated memory space pointed to by the pointer.
10. there is basically no difference between logical control and C ++. It is nothing more than conditional judgment (such as if, if else, if... else if... else) and loops (such as while, do-while, for), break, continue, and switch. The difference is that AS3 contains for... in and for each... in, which enumerate dynamic attributes. The break and continue in AS3 can use tags to control program execution processes. The Value in the case Branch of the switch in AS3 can be of any type, while the value in C ++ can only be an integer.
11. There are two declaration methods for functions in AS3: function statement Definition and function expression definition. Their differences are not described here. In C ++, there is only one declaration method (of course, independent functions or methods in the class can be considered ).
12. In AS3, all function parameters are passed in according to reference, while in C ++, values, pointers, and references are transmitted in three ways.
13. In AS3, functions cannot be overloaded (you can write the "... parameter" in the "()" of the method). Functions in C ++ can be reloaded.
14. AS3 does not have a built-in Enumeration type (which can be partially implemented using static attributes). In C ++, there is a native enum.
15. the AS3 program file contains ". fla ",". swc and. as "file, SWF file is in the Flash file format, which contains a bunch of labels that can be understood by Flash Player, and contains media resources and ABC bytecode (which is understood by Flash Player during runtime ). The FLA file is the suffix of the source file used by the FlashCS3 tool. It contains the created graphics, animation elements, and embedded media resources. The AS file is a class definition file. C ++ mainly deals with ". h" and ". cpp" files.

Ii. ActionScript3 Object-Oriented Programming
1. Define a class in AS3, which usually involves "class" and "package ". Package is mainly used to define the package path. If a Class is to be accessed externally, it must be placed in a package. In C ++, the concept of package is not used, but "include" is used to reference class definitions in other files, but not in as3.
2. in AS3, access control includes public, protected, private, and internal. If the class definition does not specify access control, internal is used by default, it indicates "accessible in the package", that is, different files in the same package can access each other's class definitions.
3. In AS3, classes are classified into dynamic classes (with dynamic keywords) and sealing classes. Additional attributes and methods can be added to dynamic classes during runtime. In C ++, there is only a seal class.
4. import other class definitions in AS3 using the "import" keyword plus the package path, and "# include" in C ++ ".
5. in inheritance, we usually need to change the content of an attribute or method from the parent class, but do not change the name to achieve polymorphism, that is, the so-called "Override ", in AS3, the keyword "final" can be used to restrict subclass rewriting, while in C ++, this keyword is not (of course, private can be used to limit the game http://www.shengshiyouxi.com ). Final can also be used to restrict the inheritance of classes. In AS3, the keyword "override" is required for rewriting. This keyword is not found in C ++.
6. When the sub-class of AS3 needs to explicitly call the method in the parent class, the super statement can be used. It can be regarded as a variable and directly hold the reference of the parent class.
7. AS3 does not provide native support for abstract classes, that is, the keyword "abstract" (which can be implemented using techniques), and the keyword "abstract" in C ++.
8. The interface class in AS3 is represented by "interface". This keyword is not found in C ++ (it can be implemented using pure virtual functions ).


Iii. ActionScript core class
1. the Array in AS3 is powerful and has many methods, similar to the containers in STL in C ++, such as vector.
2. Powerful regular expressions are introduced in AS3 and are supported by native. This function is not available in C ++.
3. XML processing in AS3 is as convenient and simple as processing native data types (strict implementation of the E4X standard), and C ++ is not.
4. AS3 has finally Exception Handling, while C ++ does not.

Other content in Flash AS3, such as Flash Player API and AS3 visual programming, are customized by Flash AS3 for Flash Player interaction and other functions. They are not comparable to C ++ and will not be described here.

 

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.