Over the past couple of years, I've really been trying to embrace my inner OOP-ness. There's been figuring things out slowly but surely and my latest wish was to externalize my libraries from my project(s).
I have a few classes here and there that it would be simpler if they were in one spot. Theoretically, if I make an update to one class it's universally updated across the board. I might need to go into older projects and add an argument here or there if that project needs an update itself, but my classes would never need to move.
Deciding where I'd like these classes to reside is a stressful thing. Forever is a long time, after all. I've been using Flex for almost a year now and I don't know why I was so reluctant to use it. Probably because I heard so many people saying "Oh, you HAVE to use Flex. You HAVE to." I alway get all obstinate when someone tells me I must do something. I'm crotchety. I tried Flex, and I never looked back.
Anyway, here are the steps. I am sure they're outlined efficiently elsewhere, but since it's new to me, it must be new to someone else and I want to save them the effort of looking. As a caveat, I never say this is
THE WAY to do things. This is
MY WAY to do things.
step 1. create a new project in Flex. Do whatever you do, name it whatever you name it, put it wherever you put it. Don't hit
Finish yet.

step 2. hit
Next. Notice the
Source Path tab with a big window underneath it? To the right of the window is an
Add Folder… button. Click
Add Folder… and find your code folder. When you click
OK, that library will be added to your project.


step 3. Hit
Finish.

Your project will be set up by flex. You'll see your project folder and inside it is
[source path] yourLibrary. In my case, it's
comThat's not all though. There is a little housecleaning in Flex I find I still need to do. Right-click on your project and choose
Properties.

In
ActionScript Compiler, deselect
Copy non-embedded files to output folder and
Generate HTML wrapper file BTW, this is a personal choice. I don't like them, so I dump them. It's up to you.

Finally, create a new Flash file and save it to your new
src folder. Now we move to;
step 4. Open the
Properties panel and under
Document Class: enter in the main class. In my case, this is
"Temporary_Project".

step 5. Now, under
Settings in the Properties panel, click the
Formats tab and change the output location of your swf to ../bin/fileName.swf fileName being the name of your file.

step 6. This is the big final set of steps that made the difference between Flash finding my class files and not. Under
Flash, choose
Preferences….

step 7. In Categories, choose
ActionScript. Click
ActionScript 3.0 Settings….

step 8. Click the bullseye and locate your code folder. Once you choose it, the path to your folder will appear in your
ClassPath: window.


And that's it. Flex will auto-complete your paths as normal, the classes will be available to your project and Flash will know where your classes are. It's a lot of screenshots, I know, but I spent 5 minutes trying to figure this out and was flummoxed at the very end when I neglected to add the Classpath to Flash.
Hope this helps.
Labels: AS3, flash, Flex