none
onLoad detection RRS feed

  • Question

  • Is there a way to determine when graphics/sound or other files have finished loading?

    When reading files from a hard drive it's usually fast enough that there isn't a problem, but when getting files from an internet url i find the program continues running before the needed graphics have finished downloading.

    An onLoad event would allow us to put up a "Downloading" screen then wait until everything is loaded before continuing the program.

    I'm not sure on the best implementation. For example, does it wait until all queued files are loaded or should we be able to tie it to the loading of specific file(s) or options for both?

    Wednesday, December 22, 2010 6:38 AM

Answers

  • Try using ImageList.LoadImage to preload all network images into memory before using them - you do this in a routine that shows a loading graphic until it is done, small example below. 

    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    loading()
    For i = 1 To 10
      GraphicsWindow.DrawResizedImage(img[i],0,0,gw,gh)
      Program.Delay(1000)
    EndFor

    Sub loading
      txt = "Loading"
      For i = 1 To 10
        txt = txt+"."
        GraphicsWindow.DrawText(50,50,txt)
        img[i] = ImageList.LoadImage(Flickr.GetRandomPicture("car"))
      EndFor
    EndSub

    I'm not sure about the internal implementation, however there is usually a workaround - if the ImageList isn't appropriate, then you will need to post a sample of the partiucular problem you are trying to code; preferably a short example that shows the issue you are having - good luck.

    EDIT

    Also, for sounds you can pre-load with Network.DownloadFile: try.

    mp3 = Network.DownloadFile("http://www. ... .mp3")
    mp3File = Program.Directory+"\file.mp3"
    GraphicsWindow.DrawText(50,50,"Done Download")
    File.CopyFile(mp3,mp3File)
    File.DeleteFile(mp3)
    Sound.Play(mp3File)


    As a final suggestion you could use the Network mothod for all file types, then you only need to download them once the first time the program is run.

    • Proposed as answer by AirWaves Friday, December 24, 2010 8:23 PM
    • Marked as answer by litdevModerator Tuesday, January 11, 2011 7:44 PM
    Wednesday, December 22, 2010 11:07 AM
    Moderator

All replies

  • Try using ImageList.LoadImage to preload all network images into memory before using them - you do this in a routine that shows a loading graphic until it is done, small example below. 

    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    loading()
    For i = 1 To 10
      GraphicsWindow.DrawResizedImage(img[i],0,0,gw,gh)
      Program.Delay(1000)
    EndFor

    Sub loading
      txt = "Loading"
      For i = 1 To 10
        txt = txt+"."
        GraphicsWindow.DrawText(50,50,txt)
        img[i] = ImageList.LoadImage(Flickr.GetRandomPicture("car"))
      EndFor
    EndSub

    I'm not sure about the internal implementation, however there is usually a workaround - if the ImageList isn't appropriate, then you will need to post a sample of the partiucular problem you are trying to code; preferably a short example that shows the issue you are having - good luck.

    EDIT

    Also, for sounds you can pre-load with Network.DownloadFile: try.

    mp3 = Network.DownloadFile("http://www. ... .mp3")
    mp3File = Program.Directory+"\file.mp3"
    GraphicsWindow.DrawText(50,50,"Done Download")
    File.CopyFile(mp3,mp3File)
    File.DeleteFile(mp3)
    Sound.Play(mp3File)


    As a final suggestion you could use the Network mothod for all file types, then you only need to download them once the first time the program is run.

    • Proposed as answer by AirWaves Friday, December 24, 2010 8:23 PM
    • Marked as answer by litdevModerator Tuesday, January 11, 2011 7:44 PM
    Wednesday, December 22, 2010 11:07 AM
    Moderator
  • Actually, the program downloads the items requested when they are asked in the code and won't continue until it has finished downloaded.

    Check this program i made. Import code: LSX899

    You need the Speech and Fremy extensions, and you can't make it work in the browser by such requirements.


    Check out my website: http://k-dev.webs.com/
    Friday, December 31, 2010 5:48 PM