Palettes and dialogs only "live" as long as your script runs. As I understand it (barely), as soon as your script 'ends', i.e., you want to work outside the panel in Illustrator, the Extendscript engine thinks the script itself has ended.
The common cure for this is to dedicate private resources to your script. You do so by creating a dedicated "engine", which will persist in memory. The following two lines do the trick when added at the very top:
#target Illustrator
#targetengine main
The first one is obsolete if you run your script from within Illustrator, but it is required if you run it from elsewhere (such as from within the Extendscript Toolkit Editor). The second sets up a private engine with a specified name; in this case main
but if you run several palettes at the same time, you need unique names for each.
See http://forums.adobe.com/thread/1238745 -- in particular, the very last post.