FlashDevelop – Fixing getDefinitionByName ReferenceError: Error #1065

This is a pretty common error to come across when you first start using FD but I thought it might help someone. Basically when you try to use a class that you have included in your SWC (such as a Bitmap or Sound with a linkage tag) using getDefinitionByName(“MyClassName”) as Class, the compiler throws an error message saying it can’t find them – variable not defined etc. Even though you think that those classes are in your SWC and therefore in your project, the compiler still doesn’t know about them so you need to tell it to include them when compiling.

There are several ways to achieve this. The most basic way is just to reference them in your code. Even a trace(MyClass) message will work or defining a dummy variable like var foo:MyClass; . The problem with this method is that you have to write a lot of dummy code to include a bunch of classes.

The correct way to do it is to actually add the SWC that the class is in to the project via Project Properties > Compiler Options > SWC Include Libraries list. This way all classes in the swc you specify are compiled. However there problem with this method is that this it includes ALL the classes in that SWC you define.

If like me you are using different classes as you develop and you don’t want to include a whole bunch of massive images the best way I have found is to include a static array with a list of the classes you want to include. So for example if I want to include a bunch of images in my SWC and call them using a string via getDefinitionByName(“MyClassName”) as Class I can force them to be included using:

private const includeClasses:Array = [MoonBMP, LavaBMP, CracksBMP];

and then later I can grab them using a string:

var ImageClass:Class = getDefinitionByName("MoonBMP") as Class;
var img:Bitmap = new ImageClass() as Bitmap;

Sorted!

Compiling multiple SWFs from FlashDevelop

I useĀ FlashDevelop for Actionscripting and sometimes I need to export multiple SWFs from a single project. You just need to use the mxmlc compiler tags in your AS class file (make sure the class extends a displayObject) and use Flash Tools > Build Current File.

Here is an example of the mxmlc with a bunch of settings that are fairly self-explanatory. For multiple SWC files just define the -l lib tag again. To see a list of all the tags use the @mxmlc -help tag.

[code]
/**
* @mxmlc -help
* @mxmlc -o bin/create_banner.swf -debug=true -default-size 1024 768 -default-background-color 0x000000 -use-network=false -l lib/login_all.swc -l lib/customFont.swc -l lib/CreateABannerAssets.swc -l lib/aether.swc -source-path=Z:\AS3_classes\
*/
[/code]