Back our Angular 4 Book on Kickstarter.

Connecting Flex 3 to a running Debugger session!

Just a reminder, that it's almost your last chance to register for Flex Camp Boston. There are only 17 tickets remaining at the time of this writing and it's only $10. I you register, be sure to put "The Flex Show" as your referrer. Did I mention that DotComIt will be giving away a Nintendo Wii at the event?

On to my post of the day...

One of the great features of Flex is that it has a step through debugger. The debugger allows you to step through code line by line to try to isolate non-obvious errors. I often find myself using this as a tool to help build better applications.

In Flex Builder 2, the compiler created two versions of your swf, a debug swf and a 'production ready' swf. If you launched the debugger (using the 'debug' option in Flex Builder), Flex Builder would create a debug session, launch the swf in a browser, and then the two could communicate. This is the button you'd use to launch the debugger:

Unfortunately, if you terminated the debug session, then reloaded the browser, you would not get a new debug session. you'd get something like this instead:

(Note: I'm sure I saw this in Flex 2 days, however I couldn't figure out how to bring it up tonight, so this screen shot is from Flex 3).

No matter how many times you click that connect button, nothing happens. That's because there is no debugger running on your machine anymore. The only way to start a debugger instance is by clicking that debug button, which automatically loads its own swf to connect to. Fortunately, there is a work around.

In Flex 3, this has improved somewhat. First off, the compiler only creates a debugger version (you can create a production ready version using "Export Release" somewhere in the menu structure). Instead of dealing with two swfs we are dealing with one. I'm not sure what the reasons are for this, but I like to think that it's due to compiler performance. It makes sense to me that the compiler will run more efficiently if it is only creating one swf instead of two. The "play" and "Debug" buttons will launch the same swf.

If you right click on a swf, you'll see a "debugger" option, like so:

If you click it, you'll go back to the connect dialog. You need a way to start a debug session not connected to any particular swf. Thankfully there is a work around. These are the steps.

  1. First bring up the Debug (or run) menu, by clicking the arrow next to the debug icon (as shown above) or the play icon (right next to it). You should see a screen like this:

    I used a screen shot from one of my current client projects and had to blank out a few of the items to prevent myself from getting yelled at.

  2. Right click on "Flex Application" and select "New". Enter a name "ProjectName Fake". Select the Project, and select the application file of the project (most likely you'll only have a single one.
  3. Uncheck the "use Defaults" box. This is where the magic happens
  4. Replace the debug URL with "about:blank". ( In the screenshot, I have the profile URL set to the same thing, but I'm not sure why )
  5. Click Apply, then debug. You're browser should open with the "about:blank" window. You'll notice that this launched a Flex Debugging instance that is not connected to a swf. Cool
  6. Switch over to a swf browser window, right click, and select that Debug option. Now you're debugging that swf.

I wouldn't be surprised if my description of how this works is a bit off, but I know it does work and it allows me to start debugging an "Application already in progress." I haven't tried it in Flex Builder 2, but I would expect it to work in some manner.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Marcel's Gravatar Not even one of the 600+ readers, has added 'Cool, thanks!' as a comment, whilst I'm sure there's a lot of people like me that are very happy with this little trick, Jeffry. So here you go:

Cool, thanks!
# Posted By Marcel | 3/10/08 7:10 PM
Jeffry Houser's Gravatar Glad you found it useful!
# Posted By Jeffry Houser | 3/10/08 8:41 PM
pestle's Gravatar FANTASTIC!!!!!!!!!!!!!!!! many many tanks!!
# Posted By pestle | 8/25/08 4:50 PM
Wlliam Mitchell's Gravatar Works great! Thanks so much for this post!
# Posted By Wlliam Mitchell | 10/1/08 11:41 PM
Oyun's Gravatar very thanks for you..
# Posted By Oyun | 11/26/08 3:32 PM
Gus's Gravatar Excellent!! works perfect with flashBuilder :D this is ideal to test and debug the application with a slow pc and with other specs

Thanks!
# Posted By Gus | 4/27/10 12:53 PM
Alpana's Gravatar Thanks a lot for the post. This is a great help
# Posted By Alpana | 5/4/10 2:16 PM
Alpana's Gravatar Thanks a lot for the post. This is a great help
# Posted By Alpana | 5/4/10 2:18 PM
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.