And here's the fix:
Function eventhook:Object(id,data:Object,context:Object)
Local event:TEvent
Local app:TApplet
event = TEvent(data)
If Not event Then Return data
app=TApplet(context)
app.OnEvent event
Return data
End Function Why does this fix things? When Bmx calls the eventhooks, it calls them in sequence until one returns Null. If Null is returned, it assumes the eventhook has handled the event and stops calling subsequent eventhooks, if the object is returned, it moves on to the next eventhook. You were "firing blanks", and so your second gadget never received a darn thing!
Sometimes you want the event to "pass through" all eventhooks, and do something with each, and this is what I've done here. This is the simplest thing to do, but means lots of unnecessary processing, and potential for bugs if you forget to check what gadget the event is intended for.
The best thing to do however, is to use the following:
Method OnEvent:Integer(Event:TEvent) Abstract
Function eventhook:Object(id,data:Object,context:Object)
Local event:TEvent
Local app:TApplet
event = TEvent(data)
If Not event Then Return data
app=TApplet(context)
If app.OnEvent(event) Return
Return data
End Function You then change your code in OnEvent to return null if it has handled the event and nothing else needs to know about it.
There's actually another issue in your OnEvent code. You are handling ALL events for ALL gagdets here. You should check that the event is related to your gadget(s) before handling it. For example, there is a timer and a canvas in each gadget. you are processing each event twice in each gadget, because you're not checking that it relates to you.
So, here's the fully fixed code (unless I missed something else of course!)
|