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.
- 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.
- 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.
- Uncheck the "use Defaults" box. This is where the magic happens
- 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 )
- 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
- 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.