Best practices and coding conventions for the officially recommended ActionScript by Adobe

Source: Internet
Author: User


 

I. Naming Conventions

1. Using naming conventions with variable names provides the following important functions:
-These conventions make the code easy to read so that you can immediately identify the data type of the variable. This helps students (persons who learn code) and developers who are not familiar with your code.
-Easy to search and replace when necessary.
-Helps reduce conflicts between reserved words and language structures.
-Helps distinguish variables of different scopes (local variables, class attributes, parameters, and so on ).

2. General naming rules
-Limit the use of acronyms. Use consistent acronyms. The acronyms must clearly represent only one meaning.
-Connect words to create names. When connecting words, use a mix of upper and lower cases to distinguish each word and improve readability.
-Name a file by describing the process or description, such as adduser.
-Do not use non-descriptive names for methods or variables.
-Keep all names as short as possible.

3. Avoid using Reserved Words and Language Structures
-Never use different cases to avoid conflicts with reserved words. For example, naming an instance of the textfield class textfield (it does not conflict with textfield because Flash is case-sensitive) is a poor coding practice.

4. Naming Variables
-Use strict data types for variables as much as possible
-All variable names must be unique.
-Do not use the same variable names with different cases.
-Do not use some words in corner 1.0 or 2.0 as the variable name.
-Do not use variables that are part of the public programming structure. Eg: Switch = true;
-Always add data type comments to the code.
-Do not use the object type too much.
-Keep variables as short as possible while keeping the meaning clear.
-To optimize a loop, use only the single-character variable name.
-The variable starts with a lowercase letter.
-Use mixed case for connected words.
-Do not use acronyms or acronyms.
-When creating a group of related variable names, use complementary pairs.

5. Naming Constants
-The constant must be an uppercase letter.
-The words to be separated should contain underscores.

6. Name a Boolean variable
-A boolean variable must start with the word "is" (because the Boolean value is essentially only "is" or "is not ).

7. Naming functions and methods
-Use descriptive names
-Use mixed case for connected words.
-The names of functions and methods start with lowercase letters.
-Describe the value to be returned in the function name.
-Create naming standards for related similar functions.
-Name the method as a verb. The connection name may be, but the name should contain verbs. Most methods are represented by verbs because the methods perform operations on objects.

8. Naming classes and objects
-The class name must start with an uppercase letter.
-When the class name is a composite or connected word, write the class name in mixed case.
-The class name is usually a noun or a qualified noun.
-The name is clearer than the name.
-Do not use acronyms or acronyms.
-Use a descriptive short name for the class content.
-Sometimes the class name is a composite word.
-Do not use plural words (such as witches or baldpirates) in the class name ).
-Do not use the class name in the class attribute because it is too long.
-Do not use a noun that can be interpreted as a verb.
-Use a unique class name for each class in an application.
-Do not name the class because it may conflict with the name of the built-in class in flash.
-Try to indicate the relationship between classes in the hierarchy.

9. Name package
-It is common to use the "Reverse Domain" naming convention. For example, you can use Com. Adobe to name adobe.com and org. yourdomain to name yourdomain.org as an example of Reverse Domain Name.
-The prefix of the package name must contain lowercase letters.
-Put related classes (classes with related functions) into the same package.
-The package name must start with a consistent prefix.
-Use a package name with clear meaning and self-explanatory nature.
-Use mixed case for the combination package name or the connected package name.
-Do not use underscores or dollar characters

10. Naming Interface
-The interface name starts with an uppercase letter "I" to help you distinguish interfaces from classes. The Interface Name iemployeerecords uses the upper-case letters and the upper-case letters.
Eg:
Interface iemployeerecords {}

-The first letter of the interface name must be capitalized.
-This Convention is the same as the class name convention.
-The interface name is generally an adjective. Eg rintable

11. Name custom components
-The first letter of the component name is in upper case, and any connected words are written in mixed case.
Eg: The following default user interface component settings use connected words and mixed upper and lower cases:
Checkbox
ComboBox
DataGrid
Datechooser
Datefield
Menubar
Numericstepper
Progressbar
Radiobutton
Scrollpane
Textarea
Textinput

-Components that do not use connected words start with an uppercase letter.

2. Use comments in the code

1. compiled comments
-Multi-line comments use block comments (/* and */), while short comments use single-line comments (//).
-Make sure that you do not use annotations for simple translation of The ActionScript code.
-Add comments to elements with unclear meanings in the code.
-Do not use confusing comments.
-Delete unnecessary comments from the code before deploying a project.

2. Add comments to the class
-Two Types of annotations in a typical class or interface file are respectively document annotations and implementation annotations.

Iii. ActionScript coding conventions

1. Save the ActionScript code in one location
2. You should try to put the codes in one location, such as one or more external ActionScript files or 2.0 frames of the timeline (when the code is placed on the timeline, this code is called a frame script ).
Do not attach code to an object

Iv. processing scope

1. Avoid using absolute targets (_ root)
2. Use _ lockroot
3. Use the this keyword

5. Build class files

1. Do not place multiple declarations on one line.
2. initialize local variables during declaration.
3. Declare variables before using them.
4. Avoid using partial declarations that hide more advanced declarations.
5. Do not assign a value to multiple variables in the statement.
6. the method or attribute is set to public only when it needs to be made public for a certain reason. Otherwise, the methods and attributes should be set to private.
7. Set most member variables as private variables unless there is good reason to set them as public variables.
8. class variables should be prefixed with "M _" eg: m_abc
9. Use the trace statement
10. If you reference a method in the parent class, you can add the super prefix to the method so that other developers can know where to call the method.
11. Avoid using the with statement

6. Use Functions

 

 


1. Try to reuse the code block as much as possible. One way to reuse code is to call a function multiple times instead of creating different codes each time.

 

 

 

 

VII. Optimization of ActionScript and Flash Player

1. Avoid calling a function multiple times from a loop.

2. Use local functions whenever possible.
3. Do not use the object type too much.
4. Avoid using eval () functions or data access operators.
5. Assign array. length to the variable before starting the loop.


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.