Cannot load images with requestImage

edited December 2013 in JavaScript Mode
This discussion was created from comments split from: My sketch in Javascript doesn't load the images....

Comments

  • edited December 2013

    I'm having an issue with the same title. I have a working program that uses @PJS and loadImage. I wanted to convert this to a lazy loader, so I removed the @PJS and substituted requestImage. I then added a loadChecker that looked at the .width property of the desired image to detect load completion.

    I'm getting a very weird result that I don't understand: some of the images don't load and report a .width = 1 (which is wrong). The deciding factor of which images load is when I try the requestImage command makes a difference Some of my images are loaded directly in the processing script like this:

    imgs = {
         fooberry:  requestImage("glifs/fooberry.png"),
         barberry:  requestImage("glifs/barberry.pnd")
        }
    

    so those images are getting requested the first time the script is run. and some of the images get requested later, specifically after the main html file binds to the processing script:

     void bindJavascript(JavaScript js) {
        var t = loadStrings("people/"+js.myIdentity+".txt");
        for (i in t) {
            imagesPeople.push( requestImage( t[i]) );
        };
    
      };
    

    The second set of images load and almost all of the first do not--but weirdly a few do.

    when I monitor the load status, I see the .width of the second set go from 0===.width to their actual width after a while. The first set immediately show a width of 1 the first time I test their .width and this never changes.

    if I put this back to loadImage() and @PJS preload then it all works fine. But that ruins the desired lazy load since everything is preloaded.

Sign In or Register to comment.