2012-06-28 6 views
-2

누군가 내게 왜 내을 얻고 있는지 말해 줄 수 있습니까?successCallback이 함수가 아닙니다.

function fillData(data){ 
     this.raw = data; 
    } 

function AnimatedModel(posx, posy, posz,sx,sy,sz,r,g,b,a, name, yd){ 
     this.x = posx; 
     this.y = posy; 
     this.z = posz; 
     this.scale = new Array(sx,sy,sz); 
     parseBinFile(this, name) 
     this.r = r; 
     this.g = g; 
     this.b = b; 
     this.a = a; 
     this.yawDeg = yd; 
     this.fillData = fillData; 
    } 

    var zombie = new AnimatedModel(0,0, 0, 0.2,0.2,0.2, 0.0,1.0,0.6,0.2, "zom3.ms3d", 0); 

function parseBinFile(model, name){ 
     getServerFileToArrayBufffer(name, model.fillData) 
     console.log(model.raw); 

    } 


    function getServerFileToArrayBufffer(url, successCallback){ 
      // Create an XHR object 
      var xhr = new XMLHttpRequest(); 
      xhr.onreadystatechange = function() { 
      if (xhr.readyState == xhr.DONE) { 
       if (xhr.status == 200 && xhr.response) { 
         // The 'response' property returns an ArrayBuffer 
         successCallback(xhr.response); 
        } else { 
         alert("Failed to download:" + xhr.status + " " + xhr.statusText); 
        } 
       } 
      } 

      // Open the request for the provided url 
      xhr.open("GET", url, true); 
      // Set the responseType to 'arraybuffer' for ArrayBuffer response 
      xhr.responseType = "arraybuffer"; 
      xhr.send(); 
     } 

편집 :

그것을 호출하는 코드 인 fillData 기능을 잊어 버렸습니다. 당신이 당신에게 문제의 원인이되는 전화입니다 그렇다면 AnimatedModelfillData 속성을 설정하기 전에 당신은 AnimatedModel 생성자 parseBinFile()를 호출

+3

음 "fillData"값의 출처는 어디입니까? 그것이 "successCallback"으로 전달하는 것입니다. 그것은 기능이 아닌 것으로 보이는 것입니다. – Pointy

+0

나는 그것을 단지 잊었다. 이전과 같은 오류. – CyanPrime

+0

'successCallback'은 함수가 아닙니다. ('getSever..'는'model.fillData'라고 불리우며, * parseBinFile이 호출 될 때까지 * 속성이 설정되지 않기 때문에 * undefined *로 평가됩니다. 따라서 successCallback은 * 정의되지 않았습니다 * : JavaScript는 * strictly입니다. 평가 *.) –

답변

2

는, 당신은 당신이 parseBinFile(this, name)를 호출하기 전에 완전히 AnimatedModel 개체를 초기화해야합니다.

+0

바로 뒤에 ...-) –

+0

@pst - 어디서? OP가 포함하고있는 코드의'fillData()'함수는 어떤 객체의 메소드가 아니며 단지 독립형 함수입니다. – jfriend00

+0

'this.fillData = fillData' ('parseBinFile (this ..) '호출 이후). 이 문제는 평가 주문의 혼동으로 인해 발생할 수 있습니다. –