roku / brightscript开发的新手:是否可以向全局关联数组(可由所有组件访问)添加一个对象,该对象的方法定义为属性之一,然后调用该方法?
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
Run Code Online (Sandbox Code Playgroud)
..然后在另一个MainController中,在运行任务并返回数据后...
MainController.brs
function init()
loadConfig()
end function
function …Run Code Online (Sandbox Code Playgroud)