Wow! Thanks a ton, extrapixel. You really shifted my thinking about using XML. I didn't realize that another thread could be running while the rest of this stuff was going. It makes sense now.
I rewrote my code so that it makes the XML requests and then a "loading..." message displays until the arrays are ready to be used.
However, I'm still having problems. I'm try to put the data retrieved in each of the XML requests into a multidimensional array, but it doesn't want to do it. Can you tell me, does this look right to you?
Code:
//store the retrieved values in a new array
for (i=0; i < headlines.length; i++) {
headlinesArr[j][i] = headlines[i];
}
I also tried this but it didn't work either:
Code: headlinesArr[j] = ml.getElementArray("entry");
Here's the full code (minus some extraneous text display, just to keep it short)... Is there something else that's not right in here that's causing this?
Code:
import simpleML.*;
// A Request object, from the library
XMLRequest xmlRequest;
int startTime; // for the timer to make request every N seconds
String[] headlines; //Array to hold date from the request
String[][] headlinesArr; //Array to hold multiple headlines arrays
// variable to check if xml request was successful
boolean xmlLoaded = false;
String[] dates = {
"2007-09-23",
"2007-09-24"
};
int x, y = 60;
int i, j = 0, k = 0;
void setup() {
size(600,400);
background(255);
startTime = millis();
// Load the font
colorMode(RGB, 255);
hint(ENABLE_NATIVE_FONTS);
font = createFont("Helvetica", 18);
for(i = 0; i < dates.length; i++) {
//make a new xml request
String url = "http://localhost:8888/sphider/data_xml.php?indexdate="+ dates[i];
xmlRequest = new XMLRequest(this, url);
xmlRequest.makeRequest();
}
frameRate(30);
}
void draw() {
if(xmlLoaded){
//go through each array of text
for (i = 0; i < headlinesArr.length; i++) {
// Every 5 seconds, draw a new line of text
int now = millis();
if (now - startTime > 5000 && k < headlinesArr[i].length) {
/*
do a bunch of stuff to display text...
*/
println(headlinesArr[i][k]);
y += 12;
k++;
startTime = now;
}
}
}
else {
// the xml hasn't finished loading into all the arrays yet, so show a loading message
background(255);
textFont(font, 12);
textAlign(CENTER);
fill(150);
text("loading...", width/2, y);
//for debugging
println("loading...");
}
}
// When the request for the XML is made
void netEvent(XMLRequest ml) {
// Retrieve an array of all XML elements inside "<entry*>" tags
headlines = ml.getElementArray("entry");
//store the retrieved values in a new array
for (i=0; i < headlines.length; i++) {
headlinesArr[j][i] = headlines[i];
}
//update the new array counter
j++;
//check if all the new arrays have been filled
if(j == dates.length) {
xmlLoaded = true;
println("xml loaded");
}
}
urrrg???