• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Calling a handler from another script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling a handler from another script


  • Subject: Calling a handler from another script
  • From: Stan Cleveland <email@hidden>
  • Date: Tue, 23 Jun 2015 14:01:17 -0700

Greetings,

I have a handler in my main script that I want to call as a method from a subclass script, but am having no luck.

I have stripped my Xcode project down to two script objects ("CtrlrAppDelegate" and "CtrlrSubclassAppDelegate"), a NIB with one button, and three resources—PNG images ("Red", "Green", and "Blue"), which look like colored LEDs. The project can be downloaded from:
http://codemunki.com/Examples/Ctrlr.zip

Initially, the button image is "Blue". Upon clicking the button, the handler "buttonClicked_" is triggered, which does these two operations:
1. Call local handler "buttonSetImage_" to set the image to "Red".
2. Call the "changeButtonImage_" handler in the subclass script, which calls back to the main script handler "buttonSetImage_" to change the image to "Green".

Stripped as bare as I can get them, here is the code from the two scripts:

-- main script
script CtrlrAppDelegate
property parent : class "NSObject"
property myButton : missing value -- wired up to button as IB outlet


on buttonClicked_(sender) -- wired up to button as IB action
-- first, change button image by direct call
buttonSetImage_("Red.png")
-- second, change button image by indirect call from subclass script
tell current application's CtrlrSubclassAppDelegate to changeButtonImage()
end buttonClicked_


on buttonSetImage_(imageName)
display dialog "Handler is executing"
set theImage to current application's NSImage's imageNamed_(imageName)
myButton's setImage_(theImage)
end buttonSetImage_


on applicationWillFinishLaunching_(aNotification)
end applicationWillFinishLaunching_


on applicationShouldTerminate_(sender)
return current application's NSTerminateNow
end applicationShouldTerminate_
end script

-- subclass script
script CtrlrSubclassAppDelegate
property parent : class "CtrlrAppDelegate"


on changeButtonImage()
tell current application's CtrlrAppDelegate to buttonSetImage_("Green.png")
end changeButtonImage_
end script

The same main-script handler ("buttonSetImage_") is called twice with a string parameter. The dialog box does pop up twice, indicating the handler is successfully called both times. When called from within the main script, it works, but when called from the subclass script, it fails to change the image. 

This is the error message (minus the timestamp) reported by Xcode:
Ctrlr[4168:303] *** +[CtrlrAppDelegate buttonSetImage:]: unrecognized function setImage_. (error -10000)

Is the failure because the subclass script is passing the parameter as (I'm guessing) a CFString? If so, how would I coerce it to an AS string? I tried "set imageName to imageName as string", but it still fails. And if that's not the issue, does anyone have an idea what is?

Many thanks,
Stan C.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Calling a handler from another script
      • From: Stan Cleveland <email@hidden>
    • Re: Calling a handler from another script
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Is it possible to run more than one ASOC App at once?
  • Next by Date: Re: Calling a handler from another script
  • Previous by thread: Re: Is it possible to run more than one ASOC App at once?
  • Next by thread: Re: Calling a handler from another script
  • Index(es):
    • Date
    • Thread