Friday, November 14, 2008

FDT swc browsing

Adobe Flash CS3 Professional IconImage via WikipediaOne of the nice things that FDT has is the ability to easily browse swc files (depending on which version you have). In Flash projects, you need swc files so that FDT is aware of library items in the fla that have class linkage set to them. You have to export the swc file and then set the swc file to your class path and viola, you can now use those library items in your project without getting errors. The alternative to this is to actually create class files that associate with the library items.

In cases where you just want to dynamically generate a MovieClip or a Bitmap, creating class files for each library item goes beyond what is needed since Flash automagically creates the class for you behind the scenes. Plus it becomes a lot of work to create a class for each and every library asset in your fla. Imagine you have dozens or even hundreds of items in your library. I'd hate to write classes for each one of those. No thanks. I'll export a swc file and be done with it.

Ok, so back to why I was writing this post. So when you create a swc file from your fla, it throws in references to every class used within the fla. This is what we want right? Not exactly. Not only does it contain references to my library assets that I do need, but it also has references to every other class used in the project. Is this bad? Functionally.........no. But having all my project classes in the swc file takes away some of the nice features that FDT offers.

When Flash creates a swc file, the basic classes look like this when browsing through them from FDT:

// Generated Source from SWC

package {
import flash.display.BitmapData;

public dynamic class ClassName extends BitmapData {
public function ClassName(XXX : Number, XXX : Number);
}
}


So this is for a bitmap in the library. Not a problem because I only use it to dynamically generate a bitmap. But for my project classes, this is no good for a couple of reasons:

1.) I don't get any of the comments or parameter names when rolling over class names, properties, or methods. Instead I see XXX for parameter names which gives no hint as to what the parameter is. And in FDT, rolling over class names, properties, or methods shows you Java doc comments. These generated classes have nothing.

2.) Control clicking any class names, properties, or methods takes you to the generated classes in the swc and not to the actual class you created in your project. This is not helpful at all. I wish that FDT looked for the class files in the project first, and then to the swc file second.

So I have a simple work around. In all my projects now, I have two fla files. The project.fla and the projectAssets.fla. What I do is copy all the library items from projects.fla and paste them in projectAssets.fla. Then I use projectAssets.fla to export the swc file. FDT doesn't care what the name of the swc file is. It will use whatever swc file you set to the class path. So now the swc file only has class references to the library items and nothing of my project class files. Very easy fix. Only thing that is a little bit tedious is you have to update each time you add new assets to the library. But it's a quick process so it's not too bad.

2 comments:

miguel said...

Hi,
Thank you for your post. I have tried to do the same with my assets but I cannot see any of them. All the code is running OK (I have set traces), but no MovieClip is shown in the screen.
Any idea where the error may be? Thank you!

Scott Enders said...

I don't understand what you mean. The only thing my method does is allow you to not have errors in FDT when trying to instantiate symbols from the library.