neo*_*ley 3 scenegraph roku brightscript
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 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
Run Code Online (Sandbox Code Playgroud)
当它到达MainController的第16行时,我得到了:
在BrightScript组件或界面中找不到成员函数。(运行时错误&hf4)在pkg:/components/MainController.brs(16)
这只是对是否可以做的一般测试,因此请不要评论这是否是“好的做法”。我只想知道是否有可能,如果可以,我在这里想念什么?谢谢你的帮助
您可以将函数作为roAssociativeArray值。实际上,这就是在BrightScript中完成OO方法的方式。
但是,不能将功能分配给Roku场景图对象(roSgNode派生)的字段!直接或间接(嵌套)。这是(当前?!)实现的限制。
您可以在此处查看RSG支持的字段类型列表https://sdkdocs.roku.com/pages/viewpage.action?pageId=1608549
是的,它确实表示支持assocarray和(最近)array-但是有一点需要注意!当您在线程之间分配(甚至访问)复合对象时,将创建一个深层副本,并且只有“受支持”的类型才能通过-并且您所体验到function的也不是其中之一。目前,所有无法识别的数据都被静默删除,甚至没有低声警告-因此,买家要当心。
有关更多信息,请参见https://forums.roku.com/viewtopic.php?f=34&t=96955&p=541965#p541965。感到受邀在Roku的开发人员论坛中添加您的声音,请求RSG支持功能类型-如果有足够多的人抱怨,他们倾向于倾听。