Script | Performs a test of the order status of the flash scripts, and concludes the following few rules:
1. Execute the frame script first, and then execute the frame script in the movie clip in the frame.
2. The execution order of frame scripts for different layers in the same frame is from the upper layer to the lower layer;
3. The order in which frames are executed in different movie clips is based on the order in which they are loaded. Movie clip scripts in different layers in the same frame are usually made from the underlying layer to the upper layer;
4. Because a movie clip that is not scripted is first loaded, it executes the script in a movie clip that is not scripted, and then executes the script in the movie clip created by the script, and the movie clips created by the script follow the "Create/load First, execute first" principle;
5. Non-script-created movie clips are loaded in order from depth to depth.
6.gotoAndPlay statement If you jump to a frame in the same movie clip, the statement that follows the statement also executes, and if you jump to another movie clip (for example, _parent.gotoandplay (n)), the subsequent statement does not execute.
The rules above are a bit like tongue twisters, so let's look at an example where I don't give the source file:
1. Create a new flash document, insert a layer, and there are two layers.
2. Insert one sentence in each of the two layers: trace ("This is layer one/two");
3. Test.
You can see the above layer output first. The swap layer position can be validated.
We continue:
1. Create a new MC, in the MC in the first frame write: Trace ("This is the film clip" +this._name);
2. Drag an MC into each of the two layers.
3. Implementation.
Go on:
1. Put the two MC on the same layer.
2. Change the order of MC, test separately.
Go on:
1. Insert the second frame.
2. Write in the second frame: gotoAndStop (1); Trace ("This is the second frame");
3. Test.
Go on:
1. Modify MC, add second frame in MC.
2. Write in the second frame: _parent.gotoandstop (1); Trace ("This is the second frame in the movie clip");
3. Remove the original two MC from the main scene.
4. The second frame of the home Scene code deletion, the new Plus: Stop ();
5. Drag the MC into a second frame.
6. Implementation.
The above rules can be validated by this.
A little reminder:
Because the order of execution is from the top layer to the bottom layer, if there is a #include in the script, it should be placed in the top layer. Such a function or variable can be referenced by the script under the layer.
Final recommendations:
In order not to be dizzy by the execution order of the Flash, please write the works according to OO thought, gotoandplay use appropriate, the reference of the variable also preferably has the encapsulation, do not refer to the same variable in the different movie clips, the global variable as far as possible not. Flash has no rules on how to write a script to be qualified, but for the convenience of work, please pay attention to the specification. Otherwise, consider the order in which the scripts are executed. The following principles may be followed:
1. Write the notes frequently.
2. Scripts are written in one frame, and scripts for different paragraphs are separated by annotations.
3. The script is written in the frame and the event handler is not added to the button/movie clip.
4. Do not use global variables.
5. Do not refer directly to a movie clip in a function, instead of a parameter reference.
6. Do not use gotoandplay frequently.
7. Commonly used functions written to the main scene frame, or write to the external file include.
8. In the movie clip, if there is a function in the frame, customize a class for the movie clip and then use the AS2.0 class link. This function is used as a method of the class. The variables in the movie clip are also the same.
9. Unless the two films really have nothing to do with it, use multiple scenes carefully.
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.