In this tutorial I'm going to show you how to organize all your classes into one folder. Flash automatically looks for classes in the same directory as your .fla file so we'll be using a classpath to access our files from another directory. So let's get to it.
Step 1 - Create A Directory
First thing we'll do is create a new folder called "classes". For this example I'm creating mine on the desktop but you can create yours anywhere you like. Inside the "classes" directory create another folder called "buttons". Inside this folder we'll keep all our classes that relate to buttons, the idea is that you orginize all your classes into different directories such as xml, tweening and mouse ect. You can create them later but for now just create the "buttons" folder inside the "classes" folder.
Step 3 - Create A Class
Open up flash and create a new ActionScript file and save the file as "button". For this example we'll be using the class file we used in the Classes Beginners Guide. This particular class scales an object when you roll over with a mouse. Copy and paste the code below and save it as "Button" inside the "buttons" folder we created in the previous step.
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class NewButton extends MovieClip {
private var Xscale:Number;
private var Yscale:Number;
public function NewButton() {
Xscale=this.scaleX;
Yscale=this.scaleY;
this.addEventListener(MouseEvent.ROLL_OVER,bigger);
this.addEventListener(MouseEvent.ROLL_OUT,smaller);
}
private function bigger(event:MouseEvent):void {
this.scaleX*= 1.5;
this.scaleY*= 1.5;
}
private function smaller(event:MouseEvent):void {
this.scaleX=Yscale;
this.scaleY=Xscale;
}
}
}
The particular line above I want you to pay attention is this line;
When you bury a class file in a directory you have have to declare that directory in the package. Our NewButton class is inside our classes/buttons folder so we declare the directory as classes.buttons
Step 3 - Create A New .fla File
We'll now create a new .fla file. Inside this fla file draw a rectangle onto the stage, convert it to a movie clip, check export for actionscript and give it the class name "mcSquare" and change the base class to "classes.buttons.NewButton". That being the directory of your class file.

Step 3 - ActionScript Settings
One final step to complete this tutorial. Inside our .fla file we have to tell flash where to look for our classes. Inside the property inspector window at the bottom click "Settings" next to publish. If you cannot see the "Settings" button click the grey area on the stage first. Inside the Publish Settings window click on setting next to the "ActionScript Version Box". That will then open up another window which will allow us to browse to our classes folder, to do this click the small target and browse to the "classes" folder.



Save all the files and test the movie.
Conclusion
This is a great way to organize all your classes into one single directory allowing for a cleaner more efficient hard drive.
This post is tagged classpath
Share This Post
Jobs


























2 Comments
Looks good. Thanks, now I feel way more confident about classes.
Hi, thanks for your time, work.. effort…. Great tutorial.. !!!
Incoming Links
Leave a Reply