New to roku/brightscript development: Is it possible to add an object to the global associative array (accessible by all components), that has a method defined as one of the properties, and call that method?
Main.brs:
function Main()
init()
end function
function init()
screen = createObject("roSGScreen")
m.port = createObject("roMessagePort")
screen.SetMessagePort(m.port)
scene = screen.CreateScene("MainController")
screen.show()
o = {
getName: function() as string
return "John"
end function
}
setUpGlobal(screen)
m.global.addFields({mainMethods: o})
while(true)
msg = wait(0, m.port)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed() then exit while
end if
end while
end function
function setUpGlobal(p_screen as Object)
m.global = p_screen.getGlobalNode()
m.global.id = "GlobalNode"
end function
.. then in another MainController, after running a task and returning data...
MainController.brs
function init()
loadConfig()
end function
function loadConfig()
m.config = createObject("roSGNode", "Configurator")
m.config.observeField("done", "onConfigLoaded")
m.config.observeField("fail", "onConfigError")
end function
function onConfigLoaded()
print "config loaded: " + m.global.mainMethods.getName()
end function
function onConfigError()
print "config failed to loaded"
end function
When it hits line 16 of MainController, I get this:
Member function not found in BrightScript Component or interface. (runtime error &hf4) in pkg:/components/MainController.brs(16)
This is just a general test of what can/can't be done so please don't comment on whether this is "good practice" or not. I just want to know if it's possible and if so, what am I missing here? Thanks for any help