I'm trying to populate a LabelList from a server using a JSON file. The parsing works fine but I can't fill out the LabelList. Here is the code and I appreciate your Help.
LabelList code:
<?xml version = "1.0" encoding = "utf-8" ?>
<!--********** Copyright 2016 Roku Corp. All Rights Reserved. **********-->
<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >
<script type = "text/brightscript" >
<![CDATA[
sub init()
m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
m.programLabel = m.top.findNode("exampleLabelList")
examplerect = m.programLabel.boundingRect()
centerx = (1280 - examplerect.width) / 2
centery = (720 - examplerect.height) / 2
m.programLabel.translation = [ centerx, centery ]
m.top.setFocus(true)
m.getHomeOptionsList = createObject("roSGNode", "getLabelListContent")
m.getHomeOptionsList.observeField("content", "showhomeoptionslist")
m.getHomeOptionsList.functionName = "showhomeoptionslist"
m.getHomeOptionsList.control = "RUN"
end sub
]]>
</script>
<children >
<LabelList id = "exampleLabelList" translation = "[160,92]" itemSize = "[440,48]">
<ContentNode role = "content" >
</ContentNode>
</LabelList>
</children>
</component>
Task code:
<?xml version = "1.0" encoding = "utf-8" ?>
<!--********** Copyright 2015 Roku Corp. All Rights Reserved. **********-->
<component name = "getLabelListContent" extends = "Task" >
<interface>
<field id = "uri" type = "uri" />
<field id = "content" type = "node" />
</interface>
<script type = "text/brightscript" >
<![CDATA[
sub init()
get_programs()
end sub
sub get_programs()
content = createObject("roSGNode", "ContentNode")
request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetMessagePort(port)
print "PARSING JSON"
on_demand_url = "http://www.example/example.json"
request.SetUrl(on_demand_url)
if (request.AsyncGetToString())
while (true)
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
json = ParseJSON(msg.GetString())
for each program in json.OnDemand.program
print program.name
listitem = content.createChild("ContentNode")
listitem.title = program.name
m.programLabel = listitem
end for
endif
else if (event = invalid)
request.AsyncCancel()
endif
end while
endif
return invalid
End sub
sub showhomeoptionslist()
print "This is the callback function!"
end sub
]]>
</script>
</component>