"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.
Edit: Actually, you also need to assign the scene variables
after calling screen.show() in your main()