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
..然後在另一個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
當它擊中線MainController的16,我得到這個:
在BrightScript組件或界面中找不到成員函數。 (運行時錯誤& HF4)在 PKG:/components/MainController.brs(16)
這是什麼可以/不可以做只是一般的測試,所以請不要對是否對此有何評論是不是「好的做法」。我只想知道這是否可能,如果是這樣,我在這裏錯過了什麼?感謝您的幫助
標記爲答案 - 感謝您的深入解釋!我會前往論壇...... :) – neoRiley