How do I load images from and array of URLs?

Hey all,
Snatching URLs from RSS, I’ve been able to populate an array of links; ran into some issues loading the images. Trying to use that array outside of its class has been problematic, and I don’t know where to place my loadImage().

Here’s the offending code:

thingTemp.prototype.update = function() {
  this.lifespan -= 2;
  for (let k = 0; k < this.link.length; k++) {
    this.link.push(photos[k].getChild('media:content').getString('url')); //populates an array with image urls
  }
};

thingTemp.prototype.display = function() {
  tint(255, this.lifespan); //changes opacity
  img = loadImage(this.link[0], success, fail);
  image(img, this.x, this.y);
};
1 Like

Additionally, I was wondering if the class.prorotype syntax was out-of-date.

Presumably, I would load my image in preload(), But thingTemp.links isn’t defined at start.

Maybe I’d refactor my code by defining links[ ] at preload therefore removing it from thingTemp class? Would that mean it wouldn’t be dynamic (i.e. images will remain the same till reload)?

Well, I’d say not out-of-date, but rather out-of-fashion. :laughing:
After all, JS got the class keyword for a couple of years now: :stuck_out_tongue_winking_eye:

2 Likes
  • You can chain-load everything from within preload().
  • 1st load the RSS, and pass a callback that will grab all of its URLs.
  • Still inside that callback, call loadImage() for each grabbed URL.
  • All the above happens before setup()!
  • The online sketch below uses loadTable() to get URLs that will later be passed to loadImage() calls within callback createPlayers():
  1. ThimbleProjects.org/gotoloop/96556
  2. ThimbleProjects.org/gotoloop/96556/sketch.js
  3. ThimbleProjects.org/gotoloop/96556/players.csv
3 Likes

<3
Thanks for the suggestion, I’ll check it out!

You’re a blessing,
Artie_sux