المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : من يترجم ويشرح ويطبق هذا المقطع


القعقاع10
09 Aug 2004, 11:04 PM
As with any language, ActionScript has syntax rules that you must follow in order to create scripts that can compile and run correctly. This section describes the elements that comprise ActionScript syntax.
Case sensitivity
In a case-sensitive programming language, variable names that differ only in case (book and Book) are considered different from each other. Therefore, it’s good practice to follow consistent capitalization conventions, such as those used in this manual, to make it easy to identify names of functions and variables in ActionScript code.
When you publish files for Flash Player 7 or later, Flash implements case sensitivity whether you are using ActionScript 1 or ActionScript 2.0. This means that keywords, class names, variables, method names, and so on are all case sensitive. For example:
//In file targeting Flash Player 7
//and either ActionScript 1 or ActionScript 2.0
//
//Sets properties of two different objects
cat.hilite = true;
CAT.hilite = true;
//Creates three different variables
var myVar = 10;
var myvar = 10;
var mYvAr = 10;
//Does not generate an error
var array = new Array();
var date = new Date();
This change also affects external variables loaded with LoadVars.load()
In addition, case sensitivity is implemented for external scripts, such as ActionScript 2.0 class files or scripts that you import using the #include command. If you are publishing files for Flash Player 7 and have previously created external files that you add to your scripts by using the #include statement, you should review each file and confirm that you used consistent capitalization throughout. One way to do this is to open the file in the Script window (Flash Professional only) or, in a new FLA file, set your publish settings to Flash Player 7 and copy the file’s contents into the Actions panel. Then use the Check Syntax button (see «Checking syntax and punctuation») or publish your file; errors that are caused by naming conflicts appear in the Output panel.
When Syntax coloring is enabled, language elements written with correct capitalization are blue by default. For more information, see «Keywords» and «Syntax highlighting»
Dot syntax
In ActionScript, a dot (.) is used to indicate the properties or methods related to an object or movie clip. It is also used to identify the target path to a movie clip, variable, function, or object.
A dot syntax expression begins with the name of the object or movie clip followed by a dot, and ends with the element you want to specify.
For example, the _x movie clip property indicates a movie clip’s x axis position on the Stage. The expression ballMC._x refers to the _x property of the movie clip instance ballMC .
As another example, submit is a variable set in the form movie clip, which is nested inside the movie clip shoppingCart . The expression shoppingCart.form.submit = true sets the submit variable of the instance form to true.
Expressing a method of an object or movie clip follows the same pattern. For example, the play() method of the ball_mc movie clip instance moves the playhead in the Timeline of ball_mc, as shown in the following statement:
ball_mc.play();
Dot syntax also uses two special aliases, _root and _parent . The alias _root refers to the main Timeline. You can use the _root alias to create an absolute target path. For example, the following statement calls the function buildGameBoard() in the movie clip functions on the main Timeline:
_root.functions.buildGameBoard();
You can use the alias _parent to refer to a movie clip in which the current object is nested. You can also use _parent to create a relative target path. For example, if the movie clip dog_mc is nested inside the movie clip animal_mc, the following statement on the instance dog_mc tells animal_mc to stop:
_parent.stop();

i&f&