How to compile the as program -- first lesson for beginners

Source: Internet
Author: User

The As script file is a text file. You can use any text editing tool to edit it and save it anywhere. To use as to control flash elements, you must associate the as code with Flash according to certain rules. Generally, there are four ways to associate the as code with flash. First, write the as code to the Flash frame. This is the most intuitive and easy to use method. However, we do not recommend that you do this except for the experiment. Second, write the as code to an external script file and insert it to the frame with the # include keyword. This method is more advanced than the first method. You can save the design and Code separately to different places. However, it is essentially no different from the first method, which is also a method that professional as programmers do not like. Third, associate external as scripts to flash components, this method is suitable for scenarios where complex images need to be drawn in the Flash Creation environment. Fourth, write the as code to external scripts and introduce them to flash using document classes. This is the recommended code writing method of as3. if you want to become an as programmer between a programmer and C programmer, Please practice this method more. The following is an example of these three script import methods.

  • Import using the # include keyword:
    (1) Create helloworld.txt, edit it in notepad, and write the code: trace ("Hello world! ");
    (2) Change the new helloworld.txt extension to..
    (3) Start flash, create a new flash file (actionscript3.0), and save it and helloworld. As to the same directory.
    (4) Select the first frame of the Flash file, press F9, open the script window, and enter include "helloworld. As" in it ";
    (5) press Ctrl + enter to test your video.

Note]

1) if the As script file is not in the same path as the flash file (. FLA file), you must specify an absolute path for the include statement. For example, in the preceding example, the storage path of helloworld. As is F:/AS/as3/lib/helloworld..
Then, the include statement should be written as include "F: // As // as3 // lib // helloworld. as "; in this case, you must add a"/"before each slash ("/") in the file path, because in the programming language, the slash must be expressed by an escape character. Only two slashes ("//") can represent a real "/"
2) In the as2 environment, the "#" symbol must be added before the include keyword, and the statement must not end with a semicolon.

  • Associate an external file with a flash component:
    (1) Create an ActionScript file and save it as helloworld.;
    (2) copy and paste the following code to the helloworld. As file.
    Package
    {
    Import flash. display. movieclip;
     
    Public class helloworld extends movieclip
    {
    Public Function helloworld ()
    {
    Trace ("helloworld ");
    }

    Public Function say (Arg: string)
    {
    Trace (ARG );
    }
    }
    }

(3) Start flash, create a new flash file (actionscript3.0), and save it and helloworld. As to the same directory.
(4) press Ctrl + F8 in the Flash environment to create a new component. The component type is video editing.
(5) Select the video clip you just created in the library, right-click it, and select "properties" from the pop-up menu"
(6) On the Component Property settings panel, select "link-export as ActionScript"
(7) Enter "helloworld" in the "class" text box (note, do not use double quotation marks)
(8) drag the component with properties set to the stage to create an instance.
(9) press Ctrl + enter to test your video.

Note]
1) the storage name of the external As script file must be the same as the class name
2) If the external script is in the package, you must enter the name of the export class in the following format: packagename. classname
2) If you want to call the "say" method in the class associated with the component in the above example on the frame, you only need to select the component instance on the stage, in the instance properties panel, name it "t_mc", and then add: t_mc.say ("Welcome to home for as") on the frame of the main timeline ");

  • Set the external as class as a document class
    (1) Create an ActionScript file and save it as helloworld.;
    (2) copy and paste the following code to the helloworld. As file.
    Package
    {
    Import flash. display. Sprite;
     
    Public class helloworld extends Sprite
    {
    Public Function helloworld ()
    {
    Trace ("helloworld ");
    }

    Public Function say (Arg: string)
    {
    Trace (ARG );
    }
    }
    }

(3) Start flash, create a new flash file (actionscript3.0), and save it and helloworld. As to the same directory.
(4) click the mouse in the blank space of the stage, and enter helloworld in the "Property panel-> document class" text box.
(5) press Ctrl + enter to test your video.
(6) To Call The say method in the helloworld class, you only need to add the function call statement to its own constructor.

Note]
1) if the external script is in the package, you must enter the document class name in the following format: packagename. classname

2) the document-based Script introduction method is only applicable to ide environments of Flash CS3 and later versions.

From: http://blog.csdn.net/hulin0229/article/details/4952017

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.