Import (import) and include as code in mxml

Source: Internet
Author: User

to improve the readability of mxml Code , you can use the label introduces the as code to replace the insert large script. You can also include (include) or import (import) as code.
There are essential differences between include and import as code. Include is to copy the code in one file to another, just as paste the content to the location where the include label is located; import) this is a reference to a class file or package. Instead, you can access the objects and attributes of an external class. The imported file must be in the source path, and the included file must be in the relative path of the mxml file, or use the absolute path.
use the label to include the as code in the flex Program .
In the block, use the import Code to define the as class or package required by the flex program.

Include as file
To include the as code, you need to introduce an external as file in the <mx: SCRIPT> tag. During compilation, the content of the AS file of the compiler is directly copied to the mxml program, which is similar to the code written directly. Like the as in the <mx: SCRIPT> block, the included as statements can only be written inside the function. However, constants and namespaces can be defined in the included as files, however, classes cannot be defined in contained files. Variables and functions defined in the include file can be referenced by any component in the mxml file.
The contained as file does not have to be placed in the same directory as the mxml file. However, the as file should be organized in a reasonable logical structure.
There are two methods in the flex program that contain external as files:
1. The source attribute of the <mx: SCRIPT> label. We recommend that you use this method to include external as files.
2. Use the include statement in the <mx: SCRIPT> block.
Note: The include command can only be used to write multi-line statements. For example, the following statements are invalid:


If (expr)

Include "foo. As"; // first statement is guarded by if, but rest are not.

...

The correct syntax is as follows:


If (expr ){
Include "foo. As"; // all statements inside {} are guarded by if.
}

Import as class or package
Import in the <mx: SCRIPT> block, for example:


Import mypackage. util. myclass; // import the specified class
Import mypackage. util. *; // use the * sign to import all classes in the util package.

Note: If the program does not use the imported class, the class will not be included in the generated SWF file. Therefore, if you use the * sign to import the complete package, the generated SWF file will not be too large.

 

 

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.