Closeing a panel attached to a window

I have set up in Interface builder a main application window called “main” in the AppleScript info panel tab, and a simple preferences panel called “preferences”. the "preferences panel has a text field input for username and one for password and a button named “prefSave”.

I attached a handler to the “Preferences” menu item (command + ,), giving it a name of “menuPref” by stating:


on choose menu item theObject
	if name of theObject is equal to "menuPref" then
		set xmlPrefs to window "preferences"
		display panel xmlPrefs attached to window "main"
		
	end if
end choose menu item

This works great, but I can’t close the attached panel!
In fact, the entire AppleScript Studio application gets “stuck” with the preferences panel attached to the window “main” and I am unable to quit (I have to force quit).

I have an on clicked section for my app and a handler for when the “prefSave” button is clicked.


	else if name of theObject is equal to "savePref" then
	set xmlPrefs to window "preferences"
	close xmlPrefs

the preferences are saved using bindings and an instance of Shared Defaults, but I don’t know how to get this darn panel to close when the user is finished entering or changing data. This entire system works fine if I get rid of the "attached to window “main” part, but It is such a tiny little panel that I would rather just drop it out of the main window than open up a separate window.

Any idea what I am doing wrong that this won’t close?

-sD-
Dr. Scotty Delicious, Scientist.

For this setup, I believe you need to use [url=http://developer.apple.com/documentation/AppleScript/Reference/StudioReference/sr10_panel_suite/sr_panel.html#//apple_ref/doc/uid/20011224-ASKPanelSuite.Commands.ClosePanel]close panel[/url].

else if theObject's name is "savePref" then
	close panel (theObject's window)
end if

Well, it kept giving me an error. I am not at home right now that I can post the exact error, but I decided to go another way with the application setup in part because this was a deal breaker, but mostly to structurally organize the app better.

-sD-
Dr. Scotty Delicious, Scientist.