So, I'm new in the whole Brightscript/Roku development environment and I'm having an issue with a request of a webservice. For ease, I made a function in the main.brs that I can call from other scripts that basically creates a roUrlTransfer object, gets the contents of the url in a variable and returns it. Here's the code:
Function vGetUrlContent(p_url As String)
url = CreateObject("roUrlTransfer")
url.SetUrl(p_url)
html = url.GetToString()
Return html
End Function
The same code (kinda) is already used successfully in the same main.brs file that has another purpose, but the same 3 lines are used.
However, when I call this function I get this error here:
BRIGHTSCRIPT: ERROR: roUrlTransfer: creating MAIN|TASK-only component failed on RENDER thread: pkg:/source/main.brs(306)
BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.
Suspending threads...
Thread selected: 1* pkg:/source/main.brs(307) url.SetUrl(p_url)
Current Function:
305: Function vGetUrlContent(p_url As String)
306: url = CreateObject("roUrlTransfer")
307:* url.SetUrl(p_url)
308: html = url.GetToString()
309: Return html
310: End Function
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/source/main.brs(307)
307: url.SetUrl(p_url)
Backtrace:
#1 Function vgeturlcontent(p_url As String) As Dynamic
file/line: pkg:/source/main.brs(307)
#0 Function onitemselected() As Void
file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(84)
Local Variables:
p_url roString (2.1 was String) refcnt=1 val:"(HERE IS THE ACTUAL WEBSERVICE URL)"
global Interface:ifGlobal
m roAssociativeArray refcnt=3 count:6
url Invalid
html <uninitialized>
Threads:
ID Location Source Code
0 pkg:/source/main.brs(80) msg = wait(0, port)
1* pkg:/source/main.brs(307) url.SetUrl(p_url)
*selected
Brightscript Debugger>
Any ideas?