
Step 6: Put all ActionScript components in packages 17
Step 5: Import classes for package-level
functions
When you use package-level functions, you must import the package. For example, in Flex 1.x
you could call the
show() method in the following way:
mx.controls.Alert.show("This is an Alert!");
In Flex 2, you must import the package before calling the function, as the following example
shows:
import mx.controls.Alert;
Alert.show("This is an Alert!");
Step 6: Put all ActionScript components
in packages
You must wrap all ActionScript components in a package statement, even if the component
is located in the same directory as the main application. If the component is in the same
directory as the main application, you can use an unnamed package, but the
package
statement must be the first line of the component’s file; for example:
package {
public class MyClass {
// Class definition
}
} // Close package
Adobe recommends that you use unique package names so that there are no duplicate class
names in your source paths. The generally accepted syntax is to use the reverse URL
technique; for example:
com.yourcompany.MyPackage
Package names must match the directory hierarchy. For example, if you have the following
component used by your main application:
/myfiles/MainApp.mxml
/myfiles/mycomponents/TrivialComponent.mxml
Your package name must be mycomponents, as the following example shows:
package mycomponents {
...
}
For more information about the package statement syntax, see “Package statement syntax”
on page 26.
Comentários a estes Manuais