Forum Discussion
haamro
8 years agoVisitor
Here is my code, did some update on getData
MyTask.xml
myfunction.brs
thank you for all your help.
MyTask.xml
<component name = "haamroContent" extends = "Task" >
<interface>
<field id = "HTTPurl" type = "string" />
<field id = "HTTPcontent" type = "string" />
</interface>
<script type = "text/brightscript" >
<![CDATA[
sub init()
m.top.functionName = "getData"
end sub
function getData()
url = m.top.HTTPurl
http = createObject("roUrlTransfer")
http.RetainBodyOnError(true)
port = createObject("roMessagePort")
http.setPort(port)
http.setCertificatesFile("common:/certs/ca-bundle.crt")
http.InitClientCertificates()
http.enablehostverification(false)
http.enablepeerverification(false)
http.setUrl(url)
if http.AsyncGetToString() Then
msg = wait(10000, port)
if (type(msg) = "roUrlEvent")
'HTTP response code can be <0 for Roku-defined errors
if (msg.getresponsecode() > 0 and msg.getresponsecode() < 400)
m.top.HTTPcontent = msg.getstring()
else
? "feed load failed: "; msg.getfailurereason();" "; msg.getresponsecode();" "; m.top.HTTPurl
m.top.HTTPcontent = ""
end if
http.asynccancel()
else if (msg = invalid)
? "feed load failed."
m.top.HTTPcontent =""
http.asynccancel()
end if
end if
end function
]]>
</script>
</component>
myfunction.brs
function getHTMLContent(webpage as string)
m.haamro = createObject("RoSGNode", "haamroContent")
m.haamro.HTTPurl=webpage
m.haamro.functionName="getdata"
m.haamro.ObserveField("HTTPcontent","gotContent")
m.haamro.control = "RUN"
end function
sub gotContent()
m.top.content = m.haamro.HTTPcontent '<================== callback triggered // content is set on Scene (myfunction.xml) where I will be using my function
print m.top.content <--- this is working and prints the output
end sub
function GrabWOD(webpage as string) <==== This is the function I am trying to call from other functions
getHTMLcontent(webpage) <-- calling my getHTMLcontent function, which triggers gotContent
html=m.top.content <-- isn't m.top.content now set ??
print html <-- not working
return html <-- not working
end function
thank you for all your help.