I know task node works like thread and not support dialog inside a task node. But, Is there any way to open a dialog box inside a task node. I also used getparent(). But no luck.
my code is below.
url="URL is Here" m.req=createobject("roURLTransfer") m.req.seturl(url) m.port=createobject("roMessagePort") m.req.setport(m.port) m.req.asyncgettostring() while true msg=wait(100,m.port) '100 millisecond pause if type(msg)="roUrlEvent" then if msg.getresponsecode()=200 then data=msg.getstring() headers=msg.getresponseheadersarray() exit while else m.req.asynccancel() ' Here I tried to print a dialog box warningdialog = CreateObject("roSGNode", "Dialog") warningdialog.title = "Warning" warningdialog.message = "Not Valid Request." warningdialog.buttons = ["Ok"] m.top.dialog = warningdialog m.top.dialog.observeField("buttonSelected", "warning") end if end if end while
Here give me a warning not to exist dialog field. Is there any other option for this?
@chaklasiyanikun wrote:...
Here give me a warning not to exist dialog field. Is there any other option for this?
seems to me you were on the right track, since wanting to display a modal dialog and that is easy to do using the .dialog field of the Scene. So you just have to grab the scene with getScene().
i'd do something like this:
dlg = createObject("roSGNode", "Dialog") port2 = createObject("roMessagePort") dlg.observeField("buttonSelected", port2) dlg.observeField("wasClosed", port2) dlg.title = "Warning" dlg.message = "Not a valid URL request" dlg.buttons = ["OK"] dlg.getScene().dialog = dlg while wait(0, port2) = invalid ' pass end while dlg.close = true 'out of propriety
A task node is not rendered so a dialog would not be visible if you could open a dialog box. If you would like a dialog to be displayed in your visibly rendered scene, you can observe a field in the task to trigger displaying a dialog.
I used both different files for both nodes. Task and scene. I used AppendChild() in a scene node to append a task node. I do not understand your answer clearly. But I think you saying like below. I will create a dialog in the scene node and also fire one trigger at the time of I append child. at the time of start trigger dialog visibility false and at time of m.req.asynccancel() visibility true. But Inside a Task node does not support m.top.dialog. The main thing is I am not able to access m.req.asynccancel() value in parent node(It's a scene). So, using this value I open dialog in the scene node. and Inside a Task node, I write an m.top.dialog But It gives an error. "dialog field doesn't exist".
I don't think you would want to append a scene to a task.
Something like this pseudo code
In your task.xml create
<interface> <field id="isCanceled" type ="boolean" alwaysnotify="true"> </interface>
In the Task logic function asyncCheck() : if asyncfail then m.top.isCanceled=true: end function
In your scene logic
myTask = TheTask
myTask.observefield("isCanceled", "onCanceled:)
mytask.control="RUN"
function onCanceled(event)
canceled=event.getdata()
if canceled=true then doDialog()
end function
I used a task node like below. Inside a scene node
m.loginscreen = CreateObject("roSGNode", "Login") m.loginscreen.observefield("isCanceled", "onCanceled") m.top.appendChild(m.loginscreen)
and create a oncanceled Function like below.
function onCanceled(event) ?"call onCanceled Event" canceled=event.getdata() if canceled=true then doDialog() end if end function
and in the XML file like this,
<field id="isCanceled" type ="boolean" alwaysnotify="true"/>
my task node logic
else
m.req.asynccancel() ' Here I tried to print a dialog box
m.top.isCanceled = true
?"m.top.isCanceled : " m.top.isCanceled
end if
and task node XML file write
<field id="isCanceled" type ="boolean" alwaysnotify="true"/>
But Here, one time call roURLTransfer and if status code is not 200 it go to else part and m.top.isCanceled call. But I'm not able to access m.top.isCanceled value in the scene node. First-time call while loop m.top.isCanceled : true this value in task node. and second time call while loop. It's gave error on msg = Wait(0, m.port) timeout. I think it's a problem with I append child. But I do not find any way to child node access in a parent.
I used a task node like below. Inside a scene node
m.loginscreen = CreateObject("roSGNode", "Login") m.loginscreen.observefield("isCanceled", "onCanceled") m.top.appendChild(m.loginscreen)
and create a oncanceled Function like below.
function onCanceled(event) ?"call onCanceled Event" canceled=event.getdata() if canceled=true then doDialog() end if end function
and in the XML file like this,
<field id="isCanceled" type ="boolean" alwaysnotify="true"/>
my task node logic
else
m.req.asynccancel() ' Here I tried to print a dialog box
m.top.isCanceled = true
?"m.top.isCanceled : " m.top.isCanceled
end if
and task node XML file write
<field id="isCanceled" type ="boolean" alwaysnotify="true"/>
But Here, one-time call roURLTransfer and if status code is not 200 it goes to else part and m.top.isCanceled call. But I'm not able to access m.top.isCanceled value in the scene node. First-time call while loop m.top.isCanceled : true this value in task node. and second time call while loop. It's gave error on msg = Wait(0, m.port) timeout. I think it's a problem with I append child. But I do not find any way to child node access in a parent.
Your login task is in a different scope than your scene you cannot access loginscreen m.top.isCanceld from the scene even though it is appended. That is why you need the observefield() from your scene to trigger your dialog. You might try setting the observer after appending logginscreen. Scene cannot observe a field that is not a child. If you are having a timeout on your msg=wait(0,m.port), that might be a different issue. are you successfully retrieving data is it is 200?
Here is Roku sample code for the basics
https://github.com/rokudev/samples/tree/master/ux%20components/control/TaskExample
Thank you, Now I understand very clearly. Yes, I successfully retrieving all response codes in the Task node. I have tried the observed after appending the login screen. But no luck. I think I will try with
m.top.observefield("isCanceled", "onCanceled")
and I successfully write a OnCanceled Function. But how can I access onCanceled(event) function in the scene node?
isCanceled
should be a field of your logintask and changed in login task
In your scene that login task is appended to and run from you will place the observer.
m.logintask.observefield("isCanceled", "onCanceled")
It is similar to the way that you should be getting your successfully retrieved data back to the scene. Just observing a different field to indicate your async canceled event.
Here, I appendchild() used that's why it's blocking the main thread. But I get a response correctly. After completing render thread execution. And I successfully access response using a global variable in a scene node. I write observeField in scene node and tried to access isCanceled field value. But, my observe field does not work in renderthread. you know any solution without appendchild access task node in the scene?