1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

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

Discussion in 'B4J Questions' started by Mashiane, Jun 21, 2019.

  1. Mashiane

    Mashiane Expert Licensed User

    Hi

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

    For example

    Code:
    '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
    Code:
    AddEvent(Me, "dblclick")
    AddEvent(Me, 
    "mouseover")
    Then on the module code we have
    Code:
    Sub game_dblclick(e As BANanoEvent)
    Log(e)
    End Sub

    Sub game_mouseover(e as bananoevent)
    'do something
    End Sub
    Thanks
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice