Path, package with #include Summary: I have recently made a relatively large stuff, accumulating some useful AS2 skills, take out some useful and share the first: Some and the feet, this dictionary is repeated ~~~~ Here Only some places you need to pay attention when using it, do not involve the contents of OOP programming. 1 # include 1.1 # inlcude is the statement used to import external scripts, so you can add a sentence in the FLAS, plus a #include "script.as", and the rest will make the volume of a small and more text editor ( Such as UltraEdit is completed. For CODER, this is a way to write code. Note that this method cannot be imported into the class, which is suitable for code such as write declaration class instance. Such as this: var P: test = new test (); p.main (); the rest of the event is given to your class, you can complete "the class is coming" ~~~~
1.2 You can set up #include in a #include to import another script file.
1.3 You can use a folder to play the following file. Suppose your file structure is arranged: Test --- // This represents Fla swf script - as.as with #include "script / as.as" or #include "script / ask.AS" You can import the script file.
2 packs and paths. In fact, when you write a package, you really pay attention to the path. 2.1 Pack in Flash is in the form of a simple folder. Import a class in a package: import mypackage.subpage.myclass; import all kinds of classes in a package: import mypackage.subpage. *;
2.2 For a statement written in the package, you must add the path to the package. Class mypackage.subpage.myclassinterface mypackage.subpackage.myinterface
2.3 Use: 2.3.1 Compared with the side, your current file storage structure is like this: test --- // This representation folder Fla SWF mypackage --- subpass1 --- myclass1.as subpage2 --- myclass2.as
If you use the class object that use to Class2 in class1, you should declare this: import mypackage.subpackage2.myclass2; class mypackage.subpage2.myclass1 {private var INS: myclass2; ...}
In the final test, don't forget that there should be one in the path option of the flash script. Note that we seem to be a ".", It represents the current FLA where the current FLA is located.
Of course, you can also choose to import relative paths without import.class mypackage.subpage2.myclass1 {private var INS: mypackage.subpackage2.myclass2; ....} However, most people should think that this is more troublesome ~ ~~~
2.3.2 IMPORT definition of starting path: How does the starting point path in the import statement calculate? The key is to see the starting point position of the script search you set in "Preferences", usually there are two items:. // Point to the current path
$ (Localdata) / classes // Points to the Flash class library, if your Flash is in the Program Files installed in the C drive, this class library should pass: "C: / Program files / macromedia / flash mx 2004 / ZH_CN / FIRST RUN / CLASSES / "View. Of course, you can also compare" personality "to set the sub-path or the parent path to the starting point path: ../ // Parent path ./subarchive/ // Level path but I am not recommended.
Therefore, all the starting paths of the class imported by Import should be based on the start path of the start path set in "Preference", and said to:
Test --- // This representation folder Fla swf mypackage --- mysuperclass.as subpage1 --- myclass1.as subpage2 --- myclass2.as
The preferences are set this setting: $ (localdata) / classes
Then MySuperClass.as wants to write: import mypackage.subpackage1.myclass1 if you want to use myclass1.as (usually refer to the member object or inheritance of the class).
Myclass2.as is used in front of myclass1.as. There is already: // The same .import mypackage.subpackage1.myclass1;
2.4 When things become complicated, maybe you will feel a little trouble, in fact, as long as you follow a principle, which class is useful in the current class / code segment, it is imported to import that type of import. For example: 2.4.1 In the main scene, use a simple factory model to switch the management class of the scene current scene, the code is as follows: VAR SceneManager: SceneMag = new scenemag (); var effectManager: ISEffect = new effect1 (); // iesffect is an interface class SceneManager.init (); EffectManager.init ();
Among them, SceneManager also has a lot of other subclasses, then, do you want to make it all in a breath? According to the principle of foregoing, it is clear, here, as long as you import the class you currently used, as follows: import sdgp.smag.scenemag; // Scene management class import sdgp.seffect. *; // effect class, there are many, all Import.
The subsequent work is to hand over the Scenemag class and the corresponding Effect class to import the class objects you want to use: Since Scencemag's declaration part I did: import sdgp.smag.csObject; // Extend the object of Object; Class, used to store some custom global properties to solve problems that do not have enumerated type IMPORT SDGP.SMag.rcsmag; // Inherited its abstract parent type IMPORT SDGP.SCOM.CSCOMPHYSCE; // Import into the Componet component package Part of the main scene of the main scene of the main scene is imported. *; // Import all the classes in the Seffect package, because here is the simple factory mode in creating the Effect object class sdgp.smag.scenemag extends rcsmag
Attachment: Simple Factory Model Implementation Part: Public Function ChangeItem (Num: Number): ISEffect // Through Interface Type, realize polymorphic creation objects. {If (Num == 0) Return New Effect1 (); Else IF Num == 1) Return New Effect2 (); Else If (Num == 2) Return New Effect3 (); Else IF (NUM == 3) Return New Effect4 (); else {trace ("unfinished items"); Return Undefined;}} 2.5 As for the use of the Flash class library, please also look at the Flash dictionary or refer to the online master-written article.
3 Summary: I hope this article can prepare some of the friends who are going to get Flash as they are as help.