As 3.0 was upgraded based on flash and as 2.0,
The first thing to note is that AS3.0 has a fundamental transformation with the previous versions.
If you were new to AS3.0 and didn't know if you would be like me, you would be caught off guard when writing code, and you would not know where to start. Because AS3.0 cannot be written in the format of AS1.0 or AS2.0.
The code is written in the external. as file (you can also write it on the timeline. Everyone is doing this, and that's all I have to do !)
The code before AS3.0 is written on the timeline in most cases. Most of the content of the current AS3.0 tutorial is written in the external. as file to cater to the principle of separation between art and code. Therefore, this requires that my code writing habits also change.
How to write? What format is used?
1. Two files, firstSample. as and firstSample. fla, which are located in the same directory.
① In firstSample.:
Package {// declare a package. It is a keyword and "required! "
Import flash. display. Sprite; // If you want to display the objects written in AS3.0, import the display object class, "required! "
Public class firstSample extends Sprite {// The Sprite object of the firstSample class file, which is displayed in the list.
Public function firstSample () {// Constructor, "required! ",
Trace ("Hey, first time ");
}
}
} // Description: the blue font is the same. "required! "
② In firstSample. fla: the document class input box is found in the attribute panel below, where the input is firstSample.
③ Press "Ctrl" + "Enter" in firstSample. fla, and the output panel displays: Hey, the first time
2. What should I do if I want to ", first time" to display it in the text in firstSample. fla?
Modify firstSample.:
Package {
Import flash. display. Sprite;
Import flash. text. TextField; // import text class, supports text operations
Public class firstSampleextends Sprite {
Public function firstSample (){
_ Txt. text = ", "; // _ txt is a dynamic text named _ txt in the firstSample. fla midfield scenario.
}
}
}
Press "Ctrl" + "Enter" in firstSample. fla to check whether the words ", "are available on firstsample.swf.
The above. as and. fla files are all in the same directory, for unified calling, and all future code will be placed in com/sxl001:
Therefore, the package must indicate the path
For example, the text firstText. as created by as is stored in com/sxl001:
① FirstTex.:
Package com. sxl001 {
Import flash. display. Sprite;
Import flash. text. TextField;
Import flash. text. TextFieldAutoSize;
Public class firstText extends Sprite {
Public function firstText (){
Var _ txt: TextField = new TextField ();
_ Txt. autoSize = TextFieldAutoSize. LEFT; // automatically adjust the text width to display the complete text
_ Txt. text = "this is the text created by ";
_ Txt. x = 200; // adjust the text position. The coordinate attribute does not need to be prefixed with x. This is a major change in AS3.0.
_ Txt. y = 150;
AddChild (_ txt); // _ txt is added to the Display List.
}
}
}
② Enter com. sxl001.firstText in the document class input box on the property panel of firstText. fla
③ Press "Ctrl" + "Enter" in firstText. fla to check whether firsttext.swf displays the text created by.