ClassPaths and Packages in Adobe Flash Cs5
In these days, when Adobe’s Flash version is up to CS5, and when the code are not anymore accepted/used on objects, the concept of Actionscript Classes are more familiar to us as each day passes. Even if we build a banner, a simple or complex application or an animated template, we create a class, type some code inside and voila – the job is done. Generally speaking, there are more than few steps to build an application, that’s way we will take a look closely on how these classes are builded.
Working with classes it’s not really rocket science, but you must set set them properly in order that your project to be well organized – so you need to show Flash where to look for them. Basically a classpath will tell to Flash where the whole organized structure of directories/sub directories are situated, which contain different classes – packages. There are two ways to do this: a global class path for all your projects you will work on – or a document-level class path separate for every new Flash file.
Setting the Global Classpath
As we’ve discussed, a global classpath can be used by any new Flash file – in present I have 2 folders -as2 (with as2 classes) and as3 (with as3 classes). What do I have for example in my folder as3? Well I used to keep there classes from Caurina, Adobe or even custom classes, for example a class for rollOver and rollOut for any button created. So I don’t have to copy these classes on any new project, each time. To set a global classpath in actionscript 3.0 you must go to Edit > Preferences (or simple CTRL+U) > ActionScript > ActionScript 3.0 Settings.
As you can see my global class path is “D:\Classes\as3” – you can create on any disk drive a folder with your classes, it will help you very well on your next project. Also, Flash will import these automatically, so you don’t have to import them anymore.
Setting the Document-Level Classpath
To setting a document-level classpath you have to follow these steps in every new flash file created: in Properties panel go to Profile > Edit (or simple CTRL+SHIFT+F12) or File > Publish Settings, near the Actionscript 3.0 dropdown choose Settings.
Here ai strongly recommend to uncheck the checkbox “Automatically declare stage instances” – by checking this you must declare all MovieClips and objects by being public variables in every class, but also this will make visible any properties/functions of that movieclip in any class, once that is declared. In source path tab, add a new path of your folder where all classes will be stored.
Don’t use an absolute path, like C:\src\mysubfolder\myclass becouse Flash will not understand where are all that classes you declared before, if you move this flash file on other computer, for example.
This is also a useful way, becouse you don’t have to type the hole path in your document class for example. Now you just type mysubfolder.myclass and that’s it.
By convention a right classpath will contain a path such as yourrojectname.yourapplicationame.yourclassfolder or other people use theirdomainextension.theirdomainname.theirprojectname – it’s ok both ways.
Another thing that I want to remind you, is that by convention your class name should never start with a lowercase character! Use more often folders – for your classes and for your movieclips inside of your Flash file, try to create a structure with not just a single or 2 classes. It will make your project more and more complicated.
Many thanks to my master, Virusescu. Cheers until next time!