Using panel information via panel ended handler


I am hard at work on my first AS Studio project. Please feel free to comment on any and all parts listed below. I have read this recent thread: about getting data back out of a panel window, but even with the boxes checked on both windows (main and newDate), it will not work. What I am trying to accomplish is a main window with a date printed that has three buttons; one to advance the date by one day, one to move back one day, and one to enter in a user defined date. The first two buttons work famously, and the date advances and retracts nicely. However, even though the new date panel comes down and accepts data input, nothing in the panel ended handler is being called.

Here is the script so far:

global to_day
property datePanel : missing value

on awake from nib theObject
	set to_day to (current date)
	my ShowDate(0)
end awake from nib

on clicked theObject
	if datePanel is equal to missing value then
		load nib "datePanel"
		set datePanel to window "newDate" --This appears to replace the [missing value] in the panelWIndow property with the name of the panel window
	end if
	(*Add your script here.*)
	if name of theObject = "nextDate" then
		my ShowDate(1)
	else if name of theObject = "back" then
		my ShowDate(-1)
	else if name of theObject = "new" then
		display panel datePanel attached to window "main"
	end if
end clicked
--This next section does not seem to be working.  I cannot get the data back from the panel window at all.
on panel ended datePanel with result theResult
	if theResult is 1 then
		tell datePanel
			set new_Month to contents of text field "month"
			set new_day to contents of text field "day"
			set new_year to contents of text field "year"
		end tell
		display dialog new_Month & space & new_day & space & new_year
		set to_day's month to new_Month
		set to_day's day to new_day
		set to_day's year to new_year
		my ShowDate(0)
	end if
end panel ended


to ShowDate(p)
	set to_day to (to_day + (p * days))
	set contents of text field "dateView" of window "main" to date string of to_day --Remember to reference the window as well
end ShowDate

I appreciate any input at all on this; I am happy to learn anything helpful.

It looks like you’ve already seen the example project. I think you just need to get the close panel command in there and have it return 1 (maybe you can add the on clicked event to a couple of buttons on your attached window).

See also: Panel Suite

Thanks for the reply, Bruce. I meant to put up the code from the .applescript file for the panel. Here it is:

on clicked theObject
	if name of theObject is "done" then
		close panel (window of theObject) with result 1
	end if
end clicked

When I click the done button, the panel closes as advertised. I believe that my syntax is correct here, but perhaps I need to do something more?

Thank you for the link to the ADC section on panels. I still think I must have introduced some small error, since it seems as though (from what I am reading) I have all the commands correct.

ADDENDUM: I changed the display panel command in my main script to simply display as recommended in the ADC panels document. No change, the panel ended handler is still not being called.

It is working now, I simply needed to check one more box in the Window Inspector to access the associated .applescript file where the panel ended handler is located.