[RESOLVED] Array of objects crashes script.
I am trying to upgrade a working page to use an array of objects. The existing page is spacepart.htm and am working on spacepart1.htm.
This is a sample of what's new:
Code:
function noteTable(thisLine) {
this.line = thisLine;
if (thisLine == "") {
this.dur = Number.POSITIVE_INFINITY
this.begPos = Number.POSITIVE_INFINITY;
this.endPos = Number.POSITIVE_INFINITY; }
else {
this.dur = 0;
this.begPos = sumMeasure * 50000 + sumBatch;
result=this.line.match(/Dur:([^\|]*)/);
if ((result != null) && (this.line.indexOf("Grace") == -1)) { // Has duration but is not grace.
var durVal = result[1];
var durLen = getNoteLength(durVal);
this.dur = durLen;
if (durLen == -1) {
alert("Illegal length: " + this.line);
return 1; }
else {
sumBatch += durLen; } // Keeping a running total of note durations in 768th notes
} // End of object with "Dur:" not a grace note
else {
if (this.line.slice(0,4) == "|Bar") {
sumBatch=0;
sumMeasure++; }
}
this.endPos = 50000 * sumMeasure + sumBatch;
}
}
function doMove() {
var result=new Array(), lineL = new Array(), lineU = new Array(), lineUarr=new Array(), lineLarr=new Array();
tempField=document.penta.UPstaff.value;
tempField=tempField.replace(/\r/g,"");
var lineU=tempField.split("\n"); // Upper staff
tempField=document.penta.DNstaff.value;
tempField=tempField.replace(/\r/g,"");
var lineL=tempField.split("\n"); // Lower staff
sumMeasure = 0, sumBatch = 0;
for (var iU=0; iU < lineU.length; iU++) { // Initial processing loop on upper staff.
lineUarr[iU] = noteTable(lineU[iU]);
} //End of initial processing of upper staff.
sumMeasure = 0, sumBatch = 0;
for (var iL=0; iL < lineL.length; iL++) { // Initial processing loop on lower staff.
lineLarr[iL] = noteTable(lineL[iL]);
} //End of initial processing of lower staff.
lineLarr[iL] = noteTable(""); // Prevents crash if there are fewer notes downstairs
iL = 1; // Code to match parts and modify if necessary
alert("Length upper = " + lineUarr.length + " length lower = " + lineLarr.length + " U lines " + lineU.length + " L lines " + lineL.length);
for (iU=1; iU < lineUarr.length; iU++) { //First line is NWC header Look for |Note| with Stem=Up specfied, not Grace, no Space=
result = lineUarr[iU].line.match(/\|Note\|Dur:.*(Grace)?.*Pos:([x#nbv]?)(-?\d*).*Stem=(Up|Down).*(Space=)?/)
if ((result != null) && (result[1] == null) && (result[5] == null)) {
while ((lineLarr[iL].dur > 0) && (lineUarr[iU].begPos > lineLarr[iL].begPos)) iL++; // Advance lower subscript until find same place in score
if (lineLarr[iL].begPos == Number.POSITIVE_INFINITY) // Ran out of notes downstairs
break;
if (lineUarr[iU].begPos < lineLarr[iL].begPos) // If went past it (syncopation?) try next line
continue;
I get an error message lineUarr[iU] is undefined but don't understand what the problem is. The value of "iU" is far less than the number of occurances when this happens. Test data are build into the demo function.
TIA