www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Array of objects crashes script.

  1. #1
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374

    resolved [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

  2. #2
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374
    Never mind. Just discovered I forgot new in these lines:
    Code:
     sumMeasure = 0, sumBatch = 0;
      for (var iU=0; iU < lineU.length; iU++) {  // Initial processing loop on upper staff.
        lineUarr[iU] = new 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] = new noteTable(lineL[iL]);
      }   //End of initial processing of lower staff.
      lineLarr[iL] = new noteTable("--");  // Prevents crash if there are fewer notes downstairs

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles