Flex3 Study Notes 3
Flex script Basics
1) Method
The concept is simple, because the basic function is the method. The method is a function in the class. For example, you can register an event listener with applicationcomplete events. Add the following attributes to the application Tag:
- Applicationcomplete = "fullnametextinput. setfocus ()"
2) Variable
A variable is a method for storing information in a program. For example:
- VaR username;
- Username = "Tom ";
- VaR username = "Tom ";
- Public var username = "Tom ";
3) Data Type
Basic data types include:
String string
Number value. The default value is Nan (not a number ")
Uint unsigned integer; default value: 0
Int integer. The default value is 0.
Boolean value. The default value is false.
Void is used as a special value of the function, indicating that no response is returned. The default value is undefined.
For example:
- Public Function dosomemath (): number {
- Return 2 + 2;
- }
4) object
Everything is an object. ActionScript is an object-oriented language. To some extent, an object is a container. It has some attributes (states) and some operations (Actions) on the attributes ). As follows:
- VaR car: Object = new object ();
- Car. type = "sports car ";
- Car. color = "red ";
- Car. topspeed = 170;
- Car. isinsured = false;
- Car. Driver = undefined;
- VaR person: Object = new object ();
- Person. Name = "Steve ";
- Person. Age = 19;
- Car. Driver = person;
5) Class
The object is a class instance. If you have a car object and you want to create another car object, that is, you have to do the same thing. What should you do? The best way is to create a car class and instantiate it twice to generate two car objects respectively. For example:
- Public class car {
- VaR type: string;
- VaR color: uint;
- VaR topspeed: int;
- VaR isinsured: Boolean;
- VaR DRIVER: person;
- }
- Public class person {
- VaR name: string;
- VaR age: int;
- }
- VaR car: Car = new car ();
- Car. type = "sports car ";
- Car. Color = 0xff0000;
- Car. topspeed = 170;
- Car. isinsured = false;
- Car. Driver = undefined;
- VaR person: person = new person ();
- Person. Name = "Steve ";
- Person. Age = 19;
- Car. Driver = person;
6) mxml and ActionScript
Mxml cannot replace ActionScript. mxml and ActionScript complement each other. Scripts are quite useful in terms of interactivity. In fact, mxml can be used to build a complete application only by using pure ActionScript. However, using mxml to create an application structure is the best method because it is easy to read and write.