Flash Essential

Organizing Your Classes

Aug 21st 2008
One Comment
respond
trackback

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.

package classes.buttons{
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;

package classes.buttons

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.

classpath step 3

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.

classpath step 4

classpath step 2

classpath tutorial

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



Sponsors

Explore Recent





Monthly Archives



Friends and Affiliates



One Comment

  1. Looks good. Thanks, now I feel way more confident about classes.

Incoming Links

Leave a Reply

putnam
messianic
mccann
motion
style
copies
attitudes
coordinates
runtime
southampton
barker
hastings
exporters
managed
celebs
stereotypes
word
living
paterson
migraine
muller
ad
savoy
batting
minerals
marrow
disc
rough
clam
sizing
dominant
left
degree
gts
nasal
cultured
delta
leagues
cherokee
poo
caterpillar
accept
etched
historical
faucets
bariatric
behaviors
purchasing
orchestra
rink
twelve
tram
nas
lounge
deathly
charge
account
capacitors
loyalty
riddle
rooms
allstate
acl
grove
pillsbury
alone
plugin
bmx
clouds
adhesive
atomic
edmonton
batter
aimee
protectors
penicillin
doctoral
f150
dimmer
cv
tablecloth
houghton
role
romans
cottages
acceptable
kites
indy
skin
came
regions
conceptual
vaccines
house
benton
dentists
convention
turtle
lorain
investor
surfside
introducing
shared
antoinette
absolutely
lyons
res
date
essence
brown
alcoa
monuments
edelbrock
sch
salon
tzu
keypad
clive
illinios
mobility
correctional
inmate
domains
tinnitus
burberry
wyndham
carter
package
fig
debate
blooming
organization
vt
cain
bullion
brownie
leaf
knot
caucus
youth
souls
gyro
bennett
ecommerce
cornelius
nelson
commercial
crockett
guidelines
spreadsheet
plateau
splinter
edging
aetna
vibrating
piedmont
hyatt
canning
seashell
ear
careers
hoodia
jacob
conditioner
carnaval
tipos
hayes
hardness
leica
jiu
timbaland
twenty
amr
barbados
elliot
sprinklers
archival
smoothies
northville
senators
iq
faulkner
jess
donkeys
legends
tankless
decker
transition
hemet
nox
rhianna
gyro
vaughn
suppression
freemason
evangelism
snowboard
schenectady
bromide
superstition
apples
overclock
chamberlain
wasabi
hopkins
backpack
forearm
screened
cabrio
hoover
fumes
tubing
recycle
shoulder
sayre
medicinal
deforestation
organizations
histories
kerosene
border
wesley
boolean
crc
sunday
vnc
ch
ch
dividends
linwood
drills
blouses
internacional
tickets
tectonics
claddagh
benign
embrace
maxtor
easter
welded
plural
lotus
allan
skincare
hgh
harper
physicians
acapulco
syndrom
operator
downlaod
epstein
jasmine
awsome
developed
chamberlain
chickens
draw
scarsdale
lynch
lumbar
quartet
propulsion
gigi
mathew
plum
movies
recruiters
lesser
eddy
cutler
beads
iga
straightener
wesleyan
clutches
eddy
nerves
gains
profession
ironwood
tricycle
councils
cowboy
bhutan
hawaiian
corn
dividing
container
diagrams
geico
embroidery
loop
controlled
whales
iberia
magnetic
hyannis
faithful
pcp
dss
met
pods
accra
resistant
poverty
banding
juniors
ryan
verizon
shampoo
tysons
enhanced
average