AS2: Packages

Packages are standard in object-oriented programming languages. A package acts as a sort of code filing system, where the package is a folder and the classes are the documents within. On your computer, a package is used to group similar classes. Packages organize your code into groups based on similarity and/or functionality.

In ActionScript 2, the syntax for package definitions doesn’t formally exist.
You can use a base package as part of a class path and create the package on your file system, but it’s strictly for organizational purposes. True package definitions let you limit access to your class definitions. In AS2 you can’t use
packages to set access limits on your class definitions; any class can import  and use any other class regardless of what package it’s in.
It is a good practice, however, to create a base package. A base package is used to group similar packages—for example, packages that belong to a particular company or organization.

class com.yourcompanyname

If your base package is based on your company name, the first part would start with your Web domain. When finished, a base package often looks like your Web address written backward.

The packages you choose to create within your base package can be anything that makes organizational sense. For example, if I had a group of utility classes, I could create a folder named utilities and add it to the base package.
class com.yourcompanyname.utilities.StringUtils

,

No comments yet.

Leave a Reply