Creating a simple class in a package – not so simple?

ENVIRONMENT: Flash CS3, ActionScript 3.0/2.0
TOPIC: packages & classes

“There are 10 types of people in this world. Those who understand binary, and those who do not.”

This is one of those little insightful jokes that truly express many of the struggles in the programming world. Most people will be confused by the above statement wondering who the other 8 people are. A few, who speak binary, will have read it naturally as dealing with two individuals. And a fair number of us geeks will have deduced from the context the twist in the words. An equally fair number of us geeks are probably still clueless. Doesn’t mean you’re stupid – just means you probably don’t deal with binary code that often.

For those entering the world of classes and packages, you might feel very akin to those wondering who the other 8 people are. If you’ve never dealt with classes (not uncommon for many web designers and programmers of older non-classed based languages – or both as the case may be for Flash developers who haven’t worked with the newer ActionScript methodologies).

Trying to understand new concepts while at the same time trying to deduce proper syntax can result in a great amount of frustration. You can have the concept understood and be unable to implement it because of a syntax issue.

A good case in point is the different implementations of packages and classes in ActionScript 2.0 versus 3.0.

For Comparison, the following defines a class in a package in AS2, where the pathname defines the package the class is a part of:

class path.classname{}

Where as in AS3, the package is designated separately from the class as shown below:

package path{
public class classname{}

This doesn’t even address the systems end of having your Flash application configured to look in the proper location of your computing platform to access the classes.

What is likely second nature and seemingly intuitive to one who has been working with packages and classes for years can in fact be a frustrating stumbling block for one entering this world for the first time. Many examples out there, and most of the official documentation, make the assumption that you already have all your pieces together. If this is not the case, (and it’s often not for someone who is new to this and thus in need of documentation), then the provided examples fail to run – breaking and leaving the programmer with little insight into the error of his or her ways.

I have attempted to provide an example from start to finish of creating and using a class in a package. Addressing both the syntactical differences between AS3 & AS2 as well as instructing the user how to configure Flash to properly look for the the classes. It is my hope that these examples will provide some useful insight to those trying to get the ball rolling.

Example 1:

(NOTE: These examples require Adobe Flash CS3)

0 Responses to “Creating a simple class in a package – not so simple?”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

August 2007

Awesome Developer Conferences

Nxtbook MediaFormer Employer - Great Company

The Saj... "Dark Lord of the SWF"