johnmarsden
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2015
12:41 PM
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?
Note: This works manually like below.. but it's why I use the `msg[xyz]()` that fails.
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
2 REPLIES 2

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2015
01:22 PM
Re: Dynamic method calling on Events
what line is failing? what would msg[checkname] be? Did you mean msg[checkname]() ?

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2015
01:26 PM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)