Shane,
Success! I finally figured how to do this by the non-protocol method, and it turns out that it’s far simpler than either of us thought (in its final structure that is, not in how much fiddling it took to get there). You don’t need to put anything in the Obj-C files other than the 2 methods, and there’s no need to do anything in the nib. You just need to make the AS a subclass of the Obj-C class and make the alert ended method in the AS the same as the one in the Obj-C class. Just like the protocol method, I don’t understand why this works. Here is what worked:
// ShowAlert.h
// NewAlert
//
#import <Cocoa/Cocoa.h>
@interface ShowAlert : NSObject {}
-(void)runSheet:(NSAlert *)anAlert onWindow:(NSWindow*)aWindow;
-(void)alertEnded:(NSAlert *)alert withButton:(NSInteger)returnCode andContext:(void *)info;
@end
// ShowAlert.m
// NewAlert
//
#import "ShowAlert.h"
@implementation ShowAlert
-(void)runSheet:(NSAlert *)anAlert onWindow:(NSWindow*)aWindow
{ [anAlert beginSheetModalForWindow:aWindow modalDelegate:self didEndSelector:@selector(alertEnded:withButton:andContext:) contextInfo:nil];}
-(void)alertEnded:(NSAlert *)alert withButton:(NSInteger)returnCode andContext:(void *)info {}
@end
script NewAlertAppDelegate
property parent : class "ShowAlert"
property NSAlert : class "NSAlert"
property button1 : missing value
property myWindow : missing value
on killProgram_(sender) --connected to button1
current application's NSApp's terminate_(me)
end killProgram_
on alertEnded_withButton_andContext_(alert, returnCode, info)
log {alert, returnCode, info}
end alertEnded_withButton_andContext_
on applicationWillFinishLaunching_(aNotification)
set messageText to "This is a message"
set infoText to "Click any button to close"
set myalert to NSAlert's alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(messageText, "OK", "Cancel", "done", infoText)
runSheet_onWindow_(myalert, myWindow)
end applicationWillFinishLaunching_
end script
The info argument of the alertEnded:withButton:andContext can be typed as (void *) as long as you pass in nil, but if you want to pass it something you can change that to (id). You can put statements inside the alertEnded:withButton:andContext: method, and they get executed as well as the ones inside the AS version of this method. I’m not sure why you need this method here even though its implementation is empty.