Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
johnmarsden
Visitor

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 2
Komag
Roku Guru

Re: Dynamic method calling on Events

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

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