I agree with MS: I'm not sure what the << On Close() function is doing either. The JSL Syntax Reference (under Help > Books) explains the On Close function differently than the Scripting Index. From the Scripting Reference: "<<On Close (expr) runs expr when the window is closed. Returns 0 if the window fails to close." So does an argument of 0 prevent the window from closing or does a window failing to close generate a 0 result from the function? Very confusing.
Getting back to the issue of your modal dialog box... I think that the << Modal command treats the "OK" and "Cancel" buttons as special buttons (same behavior as old Dialog() function). So scripts can not be attached to the "OK" and "Cancel" buttons (an error appears in the log).
So here's another approach that may work for your modal window. Create other buttons that can perform actions by attaching scripts to those buttons. The window stays open until the "OK" button is clicked. Unfortunately I don't think that you can rename the "OK" button to "Close" or allow another button to close the modal window.
Names Default To Here( 1 );
win = New Window( "Example",
<< Modal,
<< On Close ( Print( "Closed" ) ), // prints to log window
Show Menu( 0 ), Show Toolbars( 0 ), Suppress Autohide,
Text Box( "Example: Modal Dialog Window" ),
Text Box( "" ),
H List Box(
Button Box( "Say Hello", Print( "Hello" ) ), // prints to log window
Button Box( "New Window", newwin = New Window( "New Window" ) ),
Button Box( "OK" )
)
);
I have included an example of << On Close() in this script. You can see that it performs this script action when the window is closed.
Good luck!
Howard