Citation :
(Tirer de la doc de Flash)
Writing custom class files
The following example examines the parts of a class file. You learn how to write a class, and how you can modify the class to extend the ways that you can use it with Flash. You learn about the parts of a class and how to import them as well as related information about working with custom class files in Flash. You begin by looking at a very simple class. The following example shows the organization of a simple class called UserClass.
To define a class, you use the class keyword in an external script file (that is, not in a script you are writing in the Actions panel). The class structure is also pertinent for interface files. This structure is illustrated below, and following this illustration you create a class. The class file begins with documentation comments that include a general description of the code as well as author and version information. Add your import statements (if applicable). Write a package statement, class declaration, or interface declaration, as follows: class UserClass {...}
Include any necessary class or interface implementation comments. In these comments, add information that is pertinent for the entire class or interface. Add all your static variables. Write the public class variables first and follow them with private class variables. Add instance variables. Write the public member variables first, and follow them with private member variables. Add the constructor statement, such as the one in the following example: public function UserClass(username:String, password:String) {...}
Write your methods. Group methods by their functionality, not by their accessibility or scope. Organizing methods this way helps improve the readability and clarity of your code. Write the getter/setter methods into the class file. The following example looks at a simple ActionScript class named User.
To create class files:
Select File > New and then select ActionScript File, and then click OK. Select File > Save As and name the new file User.as. Type the following ActionScript code into the Script window: /**
User class
author: John Doe
version: 0.8
modified: 08/21/2005
copyright: Adobe Systems Incorporated
This code defines a custom User class that allows you to create new users and specify user login information.
*/
class User {
// private instance variables
private var __username:String;
private var __password:String;
// constructor statement
public function User(p_username:String, p_password:String) {
this.__username = p_username;
this.__password = p_password;
}
Etc,etc ......
|