Page 2 of 2

Re: OnEvent Error

Posted: 02 Jul 2021, 10:51
by emmanuel d
This does not work anymore, i get this message:

Code: Select all

Error:  Unknown method.
Specifically: Event_Close
did the syntax changed again?
iPhilip wrote:
23 May 2019, 15:38

Code: Select all

myGui := GuiCreate(,, Events)  ; Events is the "event sink object"
myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
myGui.OnEvent("Close", "Event_Close")  ; Callback is a method registered by name: Event_Close
myGui.Show

class Events {
   Event_Close(thisGui) {
      MsgBox "Closing Gui: " thisGui.title "`nand exiting."
   }
}

Re: OnEvent Error

Posted: 02 Jul 2021, 11:24
by swagfag
GuiCreate() is no more, use Gui()
the other thing that changed is instance methods are separate from class(static) methods. either create an instance of Events and use that as the sink or turn the instance method Event_Close into class method.

Code: Select all

#Requires AutoHotkey v2.0-a128+

myGui := Gui(,, Events)  ; Events is the "event sink object"
myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
myGui.OnEvent("Close", "Event_Close")  ; Callback is a method registered by name: Event_Close
myGui.Show

class Events {
   static Event_Close(thisGui) {
      MsgBox "Closing Gui: " thisGui.title "`nand exiting."
   }
}