Forum Discussion

chaklasiyanikun's avatar
6 years ago
Solved

Inside a task node open a dialogbox in Roku

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

     

10 Replies


  • 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.

    • chaklasiyanikun's avatar
      chaklasiyanikun
      Roku Guru

      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".

      • necrotek's avatar
        necrotek
        Roku Guru

        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