3

roku/brightscript 開発の新機能: プロパティの 1 つとして定義されたメソッドを持つオブジェクトをグローバル連想配列 (すべてのコンポーネントからアクセス可能) に追加し、そのメソッドを呼び出すことは可能ですか?

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) 内

これは何ができるかできないかの一般的なテストにすぎないので、これが「良い習慣」であるかどうかについてコメントしないでください。それが可能かどうか知りたいだけです。可能であれば、ここで何が欠けていますか? 助けてくれてありがとう

4

3 に答える 3

1

ノードのフィールドに関数を渡すことはできません。データのみ。m.global.mainMethods.getName設定直後に値を確認すると無効になります。

于 2016-12-21T10:40:13.433 に答える