"jul10" wrote:"maria_tarkany" wrote:
How to set a field outside the xml file?
I want to send a value when I create a scene in main function:sub Main()
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
scene = screen.CreateScene("FirstScene")
scene.url = "http://wallpaperswide.com/download/" 'HERE I want to send the url value
'in debugging mode scene.url or scene.top.url are both invalid here
screen.show()
end sub
I have this xml with "FirstScene" Scene:<?xml version="1.0" encoding="utf-8" ?>
<component name="FirstScene" extends="Scene" >
<interface>
<field id="url" type="string"/>
</interface>
<script type="text/brightscript">
<![CDATA[
sub init()
m.ep1 = m.top.createChild("Poster")
m.ep1.uri = m.top.url 'HERE I want to use the url
'But when I debug the app, in terminal the m.top.url field has no value
m.ep1.width = "264"
m.ep1.height = "148"
m.ep1.translation = "[930,500]"
end sub
]]>
</script>
</component>
In order to make this work you'll need to have an observer set up on the 'url' field in your scene.
So your init() in your FirstScene would look like this:
sub init()
m.ep1 = m.top.createChild("Poster")
m.ep1.width = "264"
m.ep1.height = "148"
m.ep1.translation = "[930,500]"
m.top.observeField("url", "onUrlChanged")
end sub
sub onUrlChanged()
m.ep1.uri = m.top.url
end sub
The rest should remain unchanged.
<?xml version="1.0" encoding="utf-8" ?>
<component name="SimpleRowListScene" extends="Scene" >
<interface>
<field id="categories" type="assocarray" onChange="categoriesChanged"/>
</interface>
<script type="text/brightscript" >
<![CDATA[
function init()
print "in init"
m.theRowList = m.top.FindNode("theRowList")
m.theRowList.SetFocus(true)
end function
function categoriesChanged() as void
print "hello"
m.top.theRowList.categories = m.top.categories
end function
]]>
</script>
<children>
<SimpleRowList id="theRowList" translation="[50,50]" />
</children>
</component>
categories = getCategoryAssociateArrayData()
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
scene = screen.CreateScene("SimpleRowListScene")
scene.categories = categories
screen.show()
while(true)
msg = wait(0, port)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed()
return true
end if
end if
end while
"bosborne" wrote:"jul10" wrote:
In order to make this work you'll need to have an observer set up on the 'url' field in your scene.
So your init() in your FirstScene would look like this:
sub init()
m.ep1 = m.top.createChild("Poster")
m.ep1.width = "264"
m.ep1.height = "148"
m.ep1.translation = "[930,500]"
m.top.observeField("url", "onUrlChanged")
end sub
sub onUrlChanged()
m.ep1.uri = m.top.url
end sub
The rest should remain unchanged.
I'm unable to get this working as well.
Here's a simple example. I want to pass in an roAssociativeArray of categories into the scene (and into the row list). Here's the code for my scene... "hello" is never even printed.<?xml version="1.0" encoding="utf-8" ?>
<component name="SimpleRowListScene" extends="Scene" >
<interface>
<field id="categories" type="assocarray" onChange="categoriesChanged"/>
</interface>
<script type="text/brightscript" >
<![CDATA[
function init()
print "in init"
m.theRowList = m.top.FindNode("theRowList")
m.theRowList.SetFocus(true)
end function
function categoriesChanged() as void
print "hello"
m.top.theRowList.categories = m.top.categories
end function
]]>
</script>
<children>
<SimpleRowList id="theRowList" translation="[50,50]" />
</children>
</component>
My brightscript main code:
categories = getCategoryAssociateArrayData()
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
scene = screen.CreateScene("SimpleRowListScene")
scene.categories = categories
screen.show()
while(true)
msg = wait(0, port)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed()
return true
end if
end if
end while
categories = getCategoryAssociateArrayData()
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.setMessagePort(port)
scene = screen.CreateScene("SimpleRowListScene")
screen.show()
scene.categories = categories
while(true)
msg = wait(0, port)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed()
return true
end if
end if
end while
"bosborne" wrote:
Here's a simple example. I want to pass in an roAssociativeArray of categories into the scene (and into the row list). Here's the code for my scene... "hello" is never even printed.<?xml version="1.0" encoding="utf-8" ?>
<component name="SimpleRowListScene" extends="Scene" >
<interface>
<field id="categories" type="assocarray" onChange="categoriesChanged"/>
</interface>
<script type="text/brightscript" >
<![CDATA[
function init()
print "in init"
m.theRowList = m.top.FindNode("theRowList")
m.theRowList.SetFocus(true)
end function
function categoriesChanged() as void
print "hello"
m.top.theRowList.categories = m.top.categories
end function
]]>
</script>
<children>
<SimpleRowList id="theRowList" translation="[50,50]" />
</children>
</component>