VerifyError: Error #1024: Stack underflow occurred

Wow – I’d never seen this one before. So I’m putting up here to remind me what to look for if I ever see it again!

Basically I had a SWF that ran fine in debug build mode in FlashDevelop but if I set it to compile as a release version this error soon appeared.
On closer inspection it turns out that in the line that was crashing (which was hard to find in itself) I was using a variable named “h” in a loop. The clue was that this var h:DisplayObject was coloured green by the compiler and therfore most likely an internal variable in a parent class. All I did was change it for something a bit more descriptive and unique and it all compiled. So lessons learnt – listen to the code highlighting hints and don’t be lazy and use short variable names!

Phew.

A bit of searching also suggested that it may be a Flex 4.1 SDK related bug as I would have assumed that the compiler would give you a warning even when compiling a debug version. If anyone can shine any more light on this one please post.

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]