Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
johnmarsden
Level 7

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
0 Kudos
2 Replies
Komag
Level 9

Re: Dynamic method calling on Events

what line is failing? what would msg[checkname] be? Did you mean msg[checkname]() ?
0 Kudos
TheEndless
Level 7

Re: Dynamic method calling on Events

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.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos