Sometimes, in your projects, there’s the need for a function to execute some general actions and you would need that function in multiple applications/projects. You could place that function inside a utilitarian class, import that class and then use that function. But what happens if you usually do not use the other functions defined in the class ? They would be imported as well, even if you don’t need them.
In this case you could define that function directly inside a package and not inside a class. This way, you only need to import the function you want to use. These functions defined in packages are called package-level functions. A good example of such a function is navigateToURL() from the flash.net package, used to open URLs, or getDefinitionByName() from the flash.utils package, used to get a reference to a class object.
The way to define a package-level function is quite simple. All you have to do is define that function like you would do it inside a class, with the exception that the function definition is located directly inside a package:
package myPackage {
public_or_internal functionName(...params):DataType {
}
}
Now, all you need to do is import the entire package (if you need it) or just that specific function (in this case the public access specifier):
import myPackage.functionName;
functionName(param1, param2...);
Note: when you save the file containing the function definition, make sure you give it the same name as the function (just like in class declarations). In this case the file name would be functionName.as.


