Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

Screengraph and AsyncGetToFile

Hello, I've created a program using screengraph, and I'm running into trouble getting notifications from urlEvent when using AsyncGetToFile. I've created a task that looks like this:

<component name="DownloadAssets" extends="Task">
   <field id = "downloadRequestID" type = "string" />
   <field id = "downloadStatus" type = "string" />
  <script type="text/brightscript">
      sub init() = "go"
        m.pendingXfers = {} = "start"
      end sub

      sub go()
        Print "Downloading Assets" = "start"
        downloadURL = ""
        xfer = CreateObject("roUrlTransfer")

        xfer.SetUrl (downloadURL)
        requestId = xfer.GetIdentity().ToStr() = requestId
        m.pendingXfers[requestId] = xfer

      end sub

      Function HandleUrlEvent(event as Object)
          requestId = event.GetSourceIdentity().ToStr()
          xfer = m.pendingXfers[requestId]
          if xfer <> invalid then
     = "done"
          end if
      End Function


I'm able to trigger the task, and I have an observer on the downloadStatus field which works (from testing by setting manually at the end of the go sub) but I never get a notification that the download completes. I'm not sure where I should put my handler for the urlEvent, if it needs to be in the task, or in the screen's brs file.
0 Kudos
Community Streaming Expert

Re: Screengraph and AsyncGetToFile

I can't say what may or may not be wrong with what you're doing, but see tim_beynart's excellent tutorial (especially Lesson 3) for an example of async requests in a task.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos