How can I use selectInput() in draw()?

Hi, I'm trying to open the File Selection window with a controlp5 button in draw() and choose an image. When I choose my image and I open it double-clicking the image, it appears in the program normally, but when I select the image and press "Open" or "Cancel" int he File Selection window, another window of selection appears again and again. Please I need help :/

Here is my code:

` import controlP5.*;

ControlP5 cp5;

PImage image; String file,pass;

void setup(){ size(1300,720);

cp5 = new ControlP5(this);

cp5.addButton("Open") .setValue(0) .setPosition(1000,100) .setSize(70,30) ; }

void draw(){

if (cp5.get(Button.class, "Open").isPressed()){ pass = "open"; file = "none"; selectInput("Select a file to process:", "fileSelected"); interrupt(); if (file != null && file != "nothing"){ image = loadImage(file); } else{ image = createImage(850,650,RGB); for (int i = 0; i < image.pixels.length; i++) { image.pixels[i] = color(0, 0, 0); } image.updatePixels();

}

}

if (pass == "open"){

image(image,0,0,800,600);

}

}

void fileSelected(File selection) { if (selection == null) { //println("Window was closed or the user hit cancel."); file = "nothing"; } else { //println("User selected " + selection.getAbsolutePath()); file = selection.getAbsolutePath(); } }

void interrupt() { while(file == "none") { noLoop(); } loop(); } `

Sign In or Register to comment.