Flash Action Code format and specification

Source: Internet
Author: User
Tags define arithmetic definition bitwise constructor expression variables visual studio
Specification
Each line statement of the Actions Acript ends with a semicolon ";". Unlike the BASIC language, the Actions cript statements, like C + +, Java, and Pascal, allow multiple lines of writing, that is, allowing a very long statement to be split into two or more lines of code, as long as there is a semicolon at the end of the line. The only drawback to allowing statement-branch writing is (at least for many people who are familiar with BASIC): You cannot forget to add a semicolon at the end of a statement. Statement branches the only limit is that the string cannot be spanned, that is, two semicolons must be on the same line.
Long-line writing is also a good layout method, such as the following statement paragraph (currently you do not need to understand what the following statement means, after the double slash is a comment):
Duplicatemovieclip ("Myoldmovieclip",//old MovieClip instance name
"Mynewmovieclip", 999); The newly replicated instance name and hierarchy
SetProperty ("MYNEWMOVIECLIPNAMEISNEWMC",//MovieClip instance name whose properties you want to modify
_alpha, "30"); Modify its transparency to 30%
But in Flash MX it seems that the automatic formatting feature is not perfect. The code above can run through, but there will be an error when using automatic formatting. The problem is the annotation statements that are inserted. After all, the example I wrote above is not very good with the syntax specification for Flash MX (but it's absolutely fine in C language syntax), so keep in mind that multiple lines of writing are used only if the statement is long or complex.
A good programmer will know how to add a comment to a program's code. But you might say, "It's okay, I know what I'm writing." But what if you read the code in 1 months ' time? Obviously, you can't remember. So what's the trouble with a few more words?
Add comments to the Actions Cript code using the following format:
statements; This is a single-line comment that starts with a double slash, followed by a comment.
statements; * This is also a comment
It's just a line change.
It's that simple (and very useful). Note/* and/* are not recommended (because they have to be paired, so they often cause errors).
In addition to annotations, another way to increase the readability of your code is to use a code layout format. Here is a section of code with high readability:
function to compute x factorial
function f (x) {
if (x<=0) {//if x is less than or equal to 0 return 1;//returns 1
} else {
Return x*f (x-1); Otherwise return factorial results
}
}
Flash MX Before the version must be the programmer's own code format, and the Flash MX Action Panel has an auto format (automatic formatting) button, you can use it to automatically format the code (also will be a grammar check, quite convenient). Formatted options can be set in the dialog box for the Auto format options item in the Action Panel pop-up menu. The following is a brief introduction to the Actions panel:
Syntax coloring and Code hints
Syntax coloring (Syntax hightlighting) is the function of the IDE (integrated development environment) of many programming languages. Flash also has this feature. The color of the syntax coloring can be Preferences in the Action Panel pop-up menu ... Item in the dialog box that corresponds to the
There is nothing to explain in detail about this. Just hope you can use syntax coloring to find errors and read code.
Flash MX's newly added code hint feature (hints) is not unfamiliar to readers who are familiar with the 6.0+ version of Visual Studio. For example, when you enter an object name and then enter ".", a list of related properties and methods is displayed. When you enter a function name and enter "(", the related function format is displayed. Specific can be in the input code of their own experience.
Syntax Specification keywords
Keywords are the basic structural units of any language program. It is a reserved word for the program language (Reserved Words) and cannot be used for other purposes (not as a custom variable, function, object name).
There are not many keywords in the Actions cript of Flash, following their list:
Flash MX Actions cript Keywords
Break jumps out of the loop body instanceof returns the class that the object belongs to (class)
Case definition A switch statement conditional selection statement block new creates a new object using the constructor (constructor)
Continue jumps to the next item in the loop body return returns a value in a function
Defaults define the default statement block switch for a switch statement to define a multiple conditional SELECT statement block
Delete clears the memory resource occupied by the specified object this refers to the object in which the current code resides
Else defines the statement block TypeOf returns the type of the object when the IF statement returns as false
A for definition a circular var declares a local variable (locally Variable)
function defines a functional statement block void Declaration return value type uncertainty
If defines a conditional statement block while defining a conditional loop statement block
In an object or element array create a loop with defines a statement block that operates on a specified object
Listing these is not to require you to recite them like memorizing words (which is why the quality of education in China is so poor), just want you to remember that there are some words in Flash that are not free to use as a keyword. This is useful when analyzing errors (especially for beginners).
Syntax Specification---case sensitive
As with C + + and Java, the Actions cript are case-sensitive.
This means that if is not equal to IF. If you use the IF in your code, you will generate an error when running and checking. Avoiding this happens is simple: pay more attention to whether the input code is automatically shaded by syntax (Syntax hightlighting).
However, for variables (Variable), instance names (Instance name) and frame labels (frame label), the Actions cript are case-insensitive. Still, I suggest that you keep the case consistent when you write your code. It's a good habit.
Syntax Specification---Operators
In addition to the keywords, the most important component of the program language is the operator. Do not say I am inflexible, because do not understand these things, you can not do anything.
The following is a list of operators, with the precedence of the operators (that is, when several operators appear in the same expression, which one is first) descending from top to bottom:

Operator description

+ One dollar (unary) plus
-One dollar (unary) minus
~ bitwise (BITWISE) Logical Non-
! Logical non (NOT)
Not logical non-(Flash 4 format)
+ + late (POST) accumulator
--Late (post) decrement
() function call
[] Array element
. Structure (Structure) member
+ + advance (Pre) accumulator
--Descending of advance (Pre)
New Create Object
Delete Object deletion
TypeOf Get Object Type
void returns undefined value
* Multiply

/except
% modulo (remainder of division)
+ Plus
Add string (String) connection (past &)
-Minus
<< move left by bit
>> Press-Right shift
>>> bitwise Right (unsigned unsigned, 0-filled)
< less than
<= less than or equal to
> Greater than
>= is greater than or equal to
LT is less than (string used)
Le less than or equal to (string used)
GT greater than (string used)
GE is greater than or equal to (string usage)
= = equals
!= is not equal to
EQ equals (String usage)
Ne not equal to (string used)
& Bitwise (bitwise) Logic and (and)
^ Bitwise logical XOR or (XOR)
| Bitwise logic or (OR)
&& logic and (and)
and logic and and (Flash 4)
|| Logical OR OR
or logical OR OR (Flash 4)
?: Conditions
= Assign Value
*= /= %=
+ = = &=
|= ^= <<=
>>= >>>=
Compound assignment operations
, multiple operations

Write such a large version (also can be said to be copied), what is the use? You'll find that these operators are no different from the C + + and Java operators, both in form and function. As a beginner you have to keep in mind the more commonly used sections (the less common part of the text background is darker). This will help you write your expressions in the future.


<!--/icon and title--><!--message-->
There are also some places to note about the use of operators.
For example and and OR, although for efficiency with && and | | There is no important difference, but if you have used BASIC in the past, you will definitely choose the former representation; If you used to use C + + or Java, then you tend to use the latter method. In my personal opinion, beginners should use the and and or with meaning to make the code highly readable.
Especially like?: This kind of extremely simplified operator is more difficult for beginners to read. For example, the following code:
x = 5;
y = 10;
z = (x < 6)? x:y; If X is less than 6, the value of x is assigned to Z, otherwise the value of y is assigned to Z
Trace (z); Return 5
Starting with the example above, all the sample code in this tutorial can be copied and pasted into the Action in the first frame of the new Flash animation. Then run it with the Test Movie of the Control menu or by pressing the key combination ctrl+enter. So you can see what the actual effect of the code is. Of course, you can also try to change the code, through the effect of changes to understand the content of the tutorial.
The following code is not as easy to understand (though very omissions):
x = 5;
y = 10;
if (x < 6) {//if x is less than 6, the value of x is assigned to Z, otherwise the value of y is assigned to Z z = x;
} else {
z = y;
}
Trace (z); Return 5
Syntax Specification---Constants
Constants are quantities that will not change in the program's operation.
such as numeric 1,2,3 ..., logical value TRUE, FALSE, and so on. In addition, there are some built-in constants, which can be seen in the contents of the Help file.
---Expression of the syntax specification
The most common statement in the Actions Cript is an expression, which is usually made up of variable names, operators, and constants. The following is a simple expression:
x = 0; The left is the variable name (x), the middle is the operator (the assignment operator "="), and the right is the constant (value 0). This is a very simple assignment expression. By this expression we can declare (Declare) a variable to prepare for the next action.
Expressions are also divided into assignment expressions, arithmetic expressions, and logical expressions.
The assignment expression above shows that the variable is given a value. An arithmetic expression, by definition, is an expression that does a mathematical operation, for example: 1+3 (The return value is number 4). A logical expression is an expression that does a logical operation, for example: 1>3. Only logical expressions return a logical value. The previous 1>3 return value is false, that is, 1 greater than 3 is false.
By combining multiple expressions together, you can compose a compound expression, which is what we use in general. For example:
t = 3*3+ (2+3);
x = 1>3; The second line above is a logical-assignment compound expression. First, Flash computes the value of the logical expression 1>3 (false), the value is then assigned to X (that is, x = False. For the operation order of a composite expression, refer to the table of operators above. To change the order of operations you can use parentheses (the first line of the example), which is consistent with other languages.
That's the end of the chapter. In the next chapter, we will discuss in detail the data types and the use of variables in Flash
Source: Flash Bar


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.