How to get the name of the current window

OK, I’ve written a handler that performs an action on selecting an item in a popup button. I would like this handler to work across windows with different names.

Here’s a code example:

set theObject to popup button "button1" of tab view item "test" of tab view "tabs" of window "mainwindow"

What I would like to do is get the name of the window then set the object as show above. I cannot find a way to get the name of the window returned to me. This seems like it would be pretty easy but I find myself stuck.

OK, I’ve managed to solve this riddle by passing the name of the “the window of theObject” to the handler as a parameter.

Here’s how I did it:

if the name of theObject is "button1" then
		set myobjectname to the name of the window of theObject
		set mycontext to mymenus's toghelp(myobjectname)
		try
			mycontext
		end try
	end if