B4J Question [BANAno] Is it possible to use a variable string to specify an event?

Mashiane

Expert
Licensed User
Hi

For .AddEventListener and .CallBack, is it possible to specify the event from a string?

For example

B4X:
'add an event
Sub AddEvent(module As Object, eventType as string)
'define the method to be called
Dim sEvent as string = $"game_${eventType}"$
Dim e as BANanoEvent
'define the callback
Dim cb as BANanoObject = BANano.CallBack(module, sEvent, Array(e))
'add the listener for the bananoobject
stage.AddEventListener(eventType, cb, false)
End Sub
Then on the parent module
B4X:
AddEvent(Me, "dblclick")
AddEvent(Me, "mouseover")
Then on the module code we have
B4X:
Sub game_dblclick(e As BANanoEvent)
Log(e)
End Sub

Sub game_mouseover(e as bananoevent)
'do something
End Sub
Thanks
 
Top