Package information in ActionScript 3

When i code in python i always try to specify information about the package in the init.py file, for example the version, author etc. Unfortunately i haven’t seen smth like this in ActionScript 3 so i started playing with ideas and here is how i solved it.

If you know python chances are that you know Django. Django is a python web framework ala ruby on rails.

In Django, to get the framework version for example, you need smth like this:

  1. import django
  2. print django.VERSION

Now, how can we do this in ActionScript 3?

Let’s say our framework structure is as follows:

framework/
framework/utils/StringUtil.as

and we want to have the framework version. We need to create a “framework.as” file at the root of the directory (same folder as the “framework” folder) like this

framework.as
framework/
framework/utils/StringUtil.as

in that framework.as file have this:

  1. package {
  2. public function get framework():Object{
  3. return {VERSION: "0.0.1"};
  4. }
  5. }

so when using the framework in flash or flex we can do this:

  1. import framework;
  2. trace (framework.VERSION);

Nice huh?

— fernando


comments

radekg

What is wrong with:
package {
public class Framework {
public static const Version:String = “1.0.0”;
}
}
?

Fernando

nothing :)

i just like it the other way better