Enabling FlashDevelop Debugger for OpenFL (Flash target)

Posted on January 17, 2015

Before I switched to Haxe, I was using FlashDevelop to write some AS3 code. From time to time a wild bug would appear and BOOM! the application stops, the stack trace appears, and FlashDevelop shows a list of local variables.

That list of local variables is a tremendous help for debugging, but wait, there’s more! The FlashDevelop debugger also enables you to use breakpoints, so it’s overall a powerful tool and I still wonder to this day how I could go without it for so long.

When I switched to Haxe, it suddenly didn’t show up anymore. At first, I was a bit concerned, but eventually I became used to coding without it and relying on other methods for debugging (much less effective). Recently, however, I ran into a particularly nasty bug, and that’s when I knew I needed the debugger.

The steps to enabling the debugger for OpenFL projects is actually very simple:

1) Add the following line to your Project.xml

<haxedef name="fdb" if="flash"/>

2) Make sure you select “debug” and not “release” when your compile

3) Open the “Project Properties” dialog, then navigate to the “Compiler Options” tab and set “Enable Debugger” to “True”.

4) This is probably the most tricky part. The debugger requires a particular version of Java to run. You need to install Java 1.6 or greater 32-bit. Then, you must set JAVA_HOME to this Java version, and make sure it’s the only or the first Java path in your PATH environment variable.

5) Find your jvm.config file:

%USERPROFILE%\AppData\Local\FlashDevelop\Apps\flexairsdk\4.6.0/bin/jvm.config

Change line 27 so that it points to the correct Java version, in my case line 27 is:

java.home=C:\Program Files (x86)\Java\jre7

6) Launch your swf with the FlashDevelop “Test” button. You should see the editor’s layout change and the debugger appear. If instead you get the following error message, it means that it’s not using the correct Java version so redo the last two steps.

        Debugger startup error. For troubleshooting see: http://www.flashdevelop.org/wikidocs/index.php?title=F.A.Q
    Error details: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
       em net.sf.jni4net.jni.JNI.Dll.JNI_GetDefaultJavaVMInitArgs(JavaVMInitArgs* args)
       em net.sf.jni4net.jni.JNI.Init()
       em net.sf.jni4net.jni.JNI.CreateJavaVM(JavaVM& jvm, JNIEnv& env, Boolean attachIfExists, String[] options)
       em net.sf.jni4net.Bridge.CreateJVM()
       em net.sf.jni4net.Bridge.CreateJVM(BridgeSetup setup)
       em FlashDebugger.DebuggerManager.Start(Boolean alwaysStart)
    [Capturing traces with FDB]

If on the other hand you don’t see any sign of the debugger launching, the problem surely lies in the first three steps.