FCS reading notes: good programming habits
Author: Liu21st Time: 2004-8-18 Document Type: Reprinted from: Liu21st's Blog View statistics year: 3737 | Quarter: 548 | Month: 548 | Week: 105 | today: 14
This section provides an overview of some of the rules that need to be followed when using ActionScript programming and creating applications, and how to make our program code more efficient and better readability, it is more convenient to debug applications. Write this section in front, and develop a developer who started contacting ActionScript programming from the beginning to develop a good programming and developing habits. 1. Follow the naming rules A application's naming plan must maintain consistency and readability. The main function or use of any entity must be able to see it clearly according to naming. Because ActionScript is a dynamic type language, naming is best to include a suffix representative object type. In general, nouns _ verbs and adjectives _ words such as nouns are the most common names, such as movie names: MY_MOVIE.SWFURL entity: course_list_output component or object name: Chat_mc variable or attribute: UserName method and variable name The construction method of lowercase letters, objects, and objects should be capitalized. When the name variable is used, the size of the case is used, and the letters are used, and the numbers and underscores can also be included. Some of the names below are illegal: _count = 5; // The first character cannot use underscore 5count = 0; // The first character cannot use the digital foo / bar = true; / / contain illegal characters, the reserved word used by ActionScript cannot be used To name the variable. ActionScript is based on ECMAScript, so we can name it according to ECMAScript specification. For example, course_list_output = "foo"; // all lowercase, use the underscore split string courseListOutput = "foo"; // Size write mixed mode baseURL = http://www.foo.com; // Constant usage all uppercase MaxCountLimit = 10; MyObject = function () {}; // Constructor f = new myObject (); // Object Note; good naming specification can also use Flash code prompt function. 2. Add a comment to your code to use code comments to make programs clearer and we will read. There are two code annotations supported by flash: single-line comments, usually used for variables varclicks = 0; // Variable for Number of Button ClickS multi-line comments, usually used for functional descriptions and large-segment text: / * Initialize The Clicks Variable That Keeps Track of the Number of TimeSthe Button Has Been Clicked. * / Some specific notes: //: TODO: Topic indicates the beginning of a topic //: bug: [bugid] Topic shows one BUG is //: Kludge: Indicates that the following code is not perfect, there may be problems //: Tricky: Tell the developer's underlying code has interactions, please be cautious before modify 3. Maintaining the overall performance of the code, should be exhaustive It may guarantee that all code is in the same location, which makes the code easier to search and debug. We have a big difficulty in debugging procedures is to locate code. If most of the code is concentrated on the same frame, the problem is better solved. Typically, we put the code in the first frame and placed separately on the top layer. If a large amount of code is concentrated in the first frame, remember to distinguish by the annotation mark and add code description at the beginning.
// =================================================== // Video voice chat System // Fcavpresence component // Copyright ◎ 2002 Macromedia, Inc. All Rights reserved.// perfection: liu21st, liu21st@126.com//----------------- -------------------------------------- In front of the independent function module, add similar labels: // ==================================================== // parameter initialization / / --------------------------------------------------- -------- 4. Initializing the app remember to initialize your application, the init function should be the first function of your application class, if you use object-oriented programming, you should be in the constructor The entry initialization work. This function is only initialized to variables and objects in the application, and other calls can be driven by event drivers. The following example can explain how to enter the initialization function function fcavpresenceclass () {this.init ();} fcavpresenceclass.prototype.init = function () {this.name = (this._name == null? "_Default_": this._name ); This.prefix = "fcavpresence." This.name ".";}; 5. Use keyword VAR using the local variable to use the keyword VAR to declare, which avoids access to global variables, more importantly, You can guarantee that the variable is not covered and confusing program logic. For example, the following code does not use VAR to declare that other variables are covered. Counter = 7; function looptest () {trace (counter); for (counter = 0; counter <5; counter ) {trace (counter); looptest (); trace (counter); output result To: 77012345 6. When you create an object, use prototypes to add methods and properties When we create an object, you should use the prototype mode to add objects or properties, so that the method or attribute can be enabled by all objects or sub-objects. access. This ability to ensure that each function in the memory has only one copy. As a general rule, do not define a method in the constructor.