successCallback不是一个函数

时间:2012-06-28 22:48:52

标签: javascript binary

有人可以告诉我为什么我会在我的js中获得successCallback is not a function吗?

这是调用它的代码:

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函数。

1 个答案:

答案 0 :(得分:2)

parseBinFile()中设置AnimatedModel属性之前,您正在fillData构造函数中调用AnimatedModel,所以如果这是导致问题的调用,那么您需要在致电AnimatedModel之前完全初始化parseBinFile(this, name)对象。