Discuss flex package

Source: Internet
Author: User
Tags modifiers

In ActionScript 3, classes are the most basic programming structure, so you must first master the basic knowledge of writing classes. For
Scholars, so all the classes must be placed in the. As file. Each as file can only define one public class, and the class name must be consistent
The file name is the same. For example, if your class name is example, the file name must be example..

All classes in ActionScript 3.0 must be placed in the package. A package is a unit used to classify classes. Its meaning is equivalent
Directory of the file system. Compared with classpath, the default class path is the root directory of the project (that is, the package
Directory containing the mxml file), so the top-level package directory is the project root directory. The package declaration is as follows:

PackageName {
}

If the class is defined in the top-level package, the package name can be left unspecified, for example:
Package{
}
When a class file is saved in a subdirectory, the package name is its storage directory. For example, if the file is saved in the example directory
The package statement is as follows:
PackageExample {
}
If the class file is saved in the subpackage subdirectory of the example directory, declare as follows:
PackageExample. subpackage {
}

The class declaration must be in the package. The followingCodeThe class example is defined in the top-level package:
Package{
Public class example {
}
}

Class subjects are defined in parentheses, including attributes and methods. The attribute is the variable associated with the class. Use the VaR keyword to declare it.
, Attributes also have modifiers to specify their range. Modifiers include:

Private
This attribute is only accessible to the class instance.
Public
This attribute can be accessed by any class instance (if it is directly accessed by class, it can be set to static)
Protected
This attribute is only accessed by its own class instance or derived class instance.
Internal
This attribute can be accessed by class instances in the package.

By default, the attribute is specified as internal unless you specify a modifier. In most cases, the attribute is specified
Private or protected. According to the conventions, both private and protected attribute names are prefixed with underscores (_).

You can use the function keyword to declare a method like a declarative function. Same as attributes,
Methods also have modifiers (public, private, protected, internal ). If the method is accessed by a class instance, you can set it to public (direct
If the method is only in the class, it is set to private or protected.

According to the Conventions, the start character of the method name must be in lowercase. Each class has a method with the same name as its own class.
Method is called a constructor. It is used to initialize a new instance. All Constructor
Functions are all public. Unlike standard methods, constructors cannot return values or declare return types.

Class files are stored in the directory that matches the package path, for example:
Com.examplecorp.net. messaging. Email. messagemanager must be saved in
The. compiler in the COM/examplecorp/NET/messaging/email/directory knows where to find the class. The compiler must also know
What is the root directory. For example, the compiler needs to know where the com directory is, And the compiler uses classpath to find the COM Object
. The default classpath isFlexOr the root directory of the flash project. For example, if the com directory and. FLA file or mxml File
The compiler can find these classes in the same directory.You can also save it to other directories.For example, if you have a public
The library is used by multiple projects. Do you need to copy multiple copies to each project? In fact, you can edit the classpath in the project to add
In this way, you can find your custom class without copying it.

Right-click the project name, select Properties, select build path, and add and modify classpath in Source Path.
Yes. If you only use the SDK, you must set classpath when compiling the project. Use mxmlc (FlexSDK package
Including the command line compiler), add the-source-path option to keep up with the class directory, for example:
Mxmlc-source-path. c: \ libraries exampleapplication.

Put all the classes in one directory (such as webroot/domain) in one of my web projects and write them in other directories.FlexThe mxml file needs to be stored in different directories according to different functional modules (for example, webroot/manage management in the background, webroot/sale on the foreground page ).

<Mx: Application xmlns: MX = "& amp; lt; a" href = "http://www.adobe.com/2006/mxml"> <mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"> </MX: Application><Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml">To use this package. </MX: Application>

<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" font = ""> <mx: Application xmlns: MX = "& amp; lt; a href = "www.adobe.com =" _ fcksavedurl = "><Mx: Application xmlns: MX = http://www.adobe.com/2006/mxml xmlns: domain = "domain. *"></MX: Application>

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.