How to develop a good habit of compiling flash ActionScript code

Source: Internet
Author: User
Tags array interface

After everyone plays flash for some time, will form their own set of flash ActionScript code writing habits. Good code writing habits can avoid low-level errors and unnecessary hassles as much as possible, thus speeding up the development process and improving the quality of development. Although the volcano is now amateur, but two years of accumulation, coupled with the "Volcano House" development, but also naturally formed a volcanic characteristics of the development habits. These habits in some way reflect my current level of development, so it is basically around the small, fast, process-oriented development model, many places are very naïve. However, with the continuous improvement of my ability, as well as the learning of object-oriented programming ideas, it must be constantly updated and perfected.

  Library Folder Classification Habits

• Sound and pictures are individually placed in separate folders.
· The MC is categorized into different folders according to the columns.
• General use of graphic elements.

  Timeline Management habits

• The top level is as layer, and if the as layer is more than three layers, create a specialized as layer folder. Multilayer as layers need to be aware of the sequence of code execution.
• The second layer is the label layer.
• Main scene other layer by column folder classification, but a MC generally only for a column, do not classify.
• Components of the same nature with little impact on one layer, other separate layers, and layered on top of each other by visual effects.
loading, transition animation, feature pages are divided into different scenes.

  Component naming habits

• The name of the components in the library: in Chinese name, after adding a specific component suffix, such as I have a "navigation" components, the button is named: "Navigation Btn", the movie clip is named: "Navigation MC." Sounds and pictures are named directly using the navigator.
• Named three-step uniformity: The name of the component in the library, the instance name in the scene, and the name of the layer to be consistent as much as possible. For example, a component in the library name is: "Navigation MC", it is in the scene of the instance name is "DAOHANG_MC", it is located in the layer name "navigation." In this way, when the number of components is very large, the amount of code written is very high, you can effectively save the naming and lookup time, while avoiding reference errors.
• Text field naming: If there is only one dynamic text field in a MC, it is named "Wenben_txt" and its variable name is "Wenben_var". If there are more than two dynamic text fields, they are named according to their capabilities.

  Architecture Habits

• Three-layer separation: Main scene data layer, animation layer, code function layer to separate. Because the data load completes, will cause the short animation to be not fluent, therefore I generally in the loading scene loads the data to complete together, then enters the animation scene. A large number of time axis animation will cause confusion in the project structure, so I usually will be the animation also processed as a stand-alone scene, the animation of the last one to copy, and then create a new feature scene and paste, all the core code is concentrated in the functional scene.
· MC structure: Because each MC basic and quite an independent small SWF, so its structure also as far as possible comply with "three layer separation" thought.
· MC Double-Jeong: Each MC is kept two-jeong. Although most of the cases can be used to complete the task of a Zhen, but I will be dedicated to a chastity, for the possibility of chastity data refresh room.
• Component nesting structure is generally not more than three layers, in the case of compelling, but also to ensure that the code is not written in the three-layer components below.
• External invocation swf all defined: _lockroot = True.
• _level0 is never used in an externally invoked SWF unless specifically required.

  Writing to process structured as code

One, code distribution
All the code is written on the timeline, usually in the first chastity, the component will never write code. The code on the main scene is responsible for the initial setup of the entire system, and the code on each MC timeline is integrated into one.

Second, the code structure
In the Code Editor, in order from top to bottom.
1 System initialization:
① interface initialization: Includes encoding settings, stage settings, component visibility, usability, and so on.
② variable initialization: The timeline or global variable initialization.
③ Array initialization: An array that is initially required and is assigned using loops.
④ Object initialization: All initially needed objects, and registers the listener.
2, the Code logic structure: Here is the entire code logic structure, generally through a series of function calls to make a variety of functions organically combined.
3, function block: Generally in the logical structure in order to define each function block, and encapsulated into the function.

Third, the naming habit
All use Chinese pinyin spelling all.
1, variable naming: Use "var" for the timeline variable declaration, and use Chinese all desperately name, example: Var liuyan= "";
2, array and object naming: Using the full spelling of the corresponding suffix, example: var shuzu_array=new array (); var liuyan_lv=new loadvars ();
3, function of the local variable naming: Using the full spell "FC" suffix, example: function Fanye (ANNIU_FC);
4, external communication variable name: external to the flash variable, add the corresponding suffix:
Example: TXT passed to flash variable use: liuyan_txt,asp is: liuyan_asp.
Flash is passed to external variables plus "flash" suffix, example: Yeshu_flash.

Iv. the habit of annotation
1, the location of the note: I am generally used to write notes in front of the code. Which is to annotate and then code first.
2, the annotation frequency: basically is the line-by-row annotation, at least is the functional annotation.
3. Annotation structure:
Module-level code is delimited by "===============".
The functional level code is delimited with "——————".
General comments are made directly with "//".

The following are some of the materials added by the classic member Noahgenius.

  1, the custom component library Management
Folders are recommended for classification. The largest category should be the functional module, for example, navigation, set up navigation folders, folders and then there is a second level of classification, I follow the picture, the button (including the MC button), MC, related to the class of MC, Home View MC (which can be used by other modules, like interface in the interface). There is also a common function module, put components, audio, video and other common components.

  2, the name of the method
Variable name landlord all said, I would like to talk about the name of the function. Recommended "Camel" trial nomenclature, from the grammatical point of view of the structure, such as Getmovieclipname (), four words, the first is a verb, in addition to the first word Weishou uppercase, such a name is better to explain the purpose of the function.

  3, improve the class of particle size, class function single
Write a few more classes do not harm, the function of the class as single as possible, do not let a class do a variety of irrelevant things, so later changes will be very troublesome.

  4, interface-based OOP programming
Java requirements for each class with a interface, in fact, not so exaggerated. But this idea is worth learning, let the interface to replace the specific implementation class interaction with other classes, if there are extensions, only need to write an implementation class, do not modify the interactive part of the code.

  5. design is more important than coding
It is absolutely impossible to write code on the first step. First plan your own system, from the big process to the small logic to achieve, as far as possible to do well. This will not be in the process of feeling confused.



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.