Re: loading an array of images?

258 views
Skip to first unread message

Lee Brunjes

unread,
Dec 10, 2012, 1:07:20 PM12/10/12
to proces...@googlegroups.com
It is difficult to tell you what your issue is from that error.

The error you pasted indicates you attempted to call the image function of processing.,js on something that was either not the processing object or the processing object failed to load.

the catch block referenced occurs during the sketch loading phase, likely indicating that something is wrong with your code.

Is there any possibility you could send us some of the code you have and we can take a look at that? It would make trouble shooting that error a bit easier.

-Lee


On Mon, Dec 10, 2012 at 11:07 AM, protonum <polif...@gmail.com> wrote:
I'm parsing a .csv file and using the names I find there to upload images from a subfolder. Whatever I do, it won't work. Off course I tried preloading the images with directives. I tried placing the images on the same folder and loading directly, preloading the images on the document via javascript, like I saw some people doing... Everytime I ony get this error.

TypeError: $this_1.image is not a function
} catch(e) {

processing.js (line 10130)

How can I achieve this? Somebody has an example on how to load multiple images which urls are saved on a text file??? Please...

--
You received this message because you are subscribed to the Google Groups "Processing.js" group.
To view this discussion on the web visit https://groups.google.com/d/msg/processingjs/-/6dQyKlLB5q0J.
To post to this group, send email to proces...@googlegroups.com.
To unsubscribe from this group, send email to processingjs...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/processingjs?hl=en.

protonum

unread,
Dec 10, 2012, 3:17:23 PM12/10/12
to proces...@googlegroups.com
Thanks Lee. I didn't post first, because the code is long and has lots of stuff dealing with data mining etc. I made a minimal version of it. It gives me the same error. So maybe the error is not that bad, I'm just not a webprogrammer at all. I also tried loading the image in the makeFlags() method and passing it as a parameter, but it's still the same.

/*@pjs preload="flags/Syria.png,flags/Lebanon.png,flags/Algeria.png";*/
Flag [] flags;
String [] names = {"Algeria","Lebanon","Syria"};
int rowCount = names.length;

void setup(){
  size(200,200);
  makeFlags();
}

void draw(){
   for (int i = 0; i < rowCount; i++) {
      flags[i].render();
   }
}

void makeFlags() {
  flags = new Flag[rowCount];
  for (int i = 0; i < rowCount; i++) {
    flags[i]=new Flag(i, names[i]);
    print("flags/"+flags[i].name+".png,");
  }
}
class Flag {
  PVector pos;
  int id;
  int[]stats;
  String name;
  int countryRisk;
  int w, h;
  PImage image;



  public Flag(int index, String nm) {
    pos = new PVector();
    id = index;
    name = nm;
    String url = "flags/"+name+".png";

    image = loadImage(url);

    w =50;
    h = 25;
    float py = h*id + 50;
    pos.y = py + id*10 ;
    pos.x = random(width);
  }
 
 
  public void render(){
    fill(60);
    stroke(200);
    if(image!=null){image(image, pos.x, pos.y, w, h);}
    else {rect(pos.x, pos.y, w, h);println("NULL");}
    //rect(pos.x, pos.y, w, h);

protonum

unread,
Dec 11, 2012, 6:03:06 AM12/11/12
to proces...@googlegroups.com
Hi,

I solved it. Uusing a class to render the image was the problem. I loaded the images on a global array and just use the class to compute positions and now it's working.
Thanks!
Reply all
Reply to author
Forward
0 new messages