Dynamic method calling on Events

I’m trying to dynamically call a method on an event but I get an error saying: “Array operation attempted on variable not DIM’d. (runtime error &he7) in xyz”

This methodology works fine for my roAssociativeArrays, but doesn’t seem to work on the actual events broadcast from the remote. Is there a way to dynamically execute a method that exists on an event?


m.events = ["ListItemFocused", "ListItemSelected"] 'arbitrary events for sake of example

                for each event in m.events
                    checkName = "is" + event
                    handlerName = "on" + event

                    if msg <> invalid and msg[checkName] then
                        print "Success."
                        m[handlerName](msg)
                    end if
                end for

Note: This works manually like below.. but it’s why I use the msg[xyz]() that fails.


' ordinarily, this would work, and that's great.. but not what I'm trying to achieve

                'if msg.isScreenClosed() then
                '    m.onScreenClosed(msg)
                'end if

what line is failing? what would msg[checkname] be? Did you mean msgcheckname ?

As you’ve discovered, you cannot use roAssociativeArray syntax on an event. Your best bet is probably to find out what ifXXXXEvent.GetType() value each event you’re trying to capture returns, and compare that instead. The GetType() values used to be documented, but for some reason Roku removed them, so you’ll probably have to capture each event in a debug session to get the values.