« Wii & Flash games for Visa | Home | ActionScript 3 Cronjob [beta] »

June 8, 2008

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:
import django 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:
package { public function get framework():Object{ return {VERSION: "0.0.1"}; } }

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

import framework; trace (framework.VERSION);

Nice huh?

-- fernando

2 Comments

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

nothing :)

i just like it the other way better

About this Entry

This page contains a single entry by fernando published on June 8, 2008 8:40 PM.

Wii & Flash games for Visa was the previous entry in this blog.

ActionScript 3 Cronjob [beta] is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.