2014-05-19 2 views
0

안녕하세요. 첫 번째 모습에서이 질문은 이미 대답했지만, 내가 찾은 대답으로 내 문제를 해결할 수는 없다고 생각합니다.잡히지 않은 TypeError : 프로토 타입 함수에서 정의되지 않은 'value'속성을 읽을 수 없습니다.

하나의 클래스가 있는데 함수 중 하나가 다른 함수를 호출해야합니다 ("self"메쉬를 전달하면됩니다). 문제가 있습니다. 어딘가에서 참조를 잃어 버리고 어디에 있는지 찾을 수 없습니다. . 여기

코드, 그리고 미리 감사드립니다 :)

//classe unit. 
function unit(unitId, mesh, unitName, shieldSize, armor, armorTechLvl, shieldTechLvl, employeesNeeded, description, imageFilePath, structureNeeded, storageSize, unitSpeed, attackPower, weaponTech) { 
    var unitId; 
    var unitName; 
    var shieldSize; 
    var armor; 
    var armorTechLvl; 
    var shieldTechLvl; 
    var employeesNeeded; 
    var description; 
    var imageFilePath; 
    var structureNeeded; 
    var storageSize; 
    var unitSpeed; 
    var attackPower; 
    var weaponTech; 
    var shipposx; 
    var shipposz; 
    var mesh; 
    this.unitId = unitId; 
    this.unitName = unitName; 
    this.shieldSize = shieldSize; 
    this.armor = armor; 
    this.armorTechLvl = armorTechLvl; 
    this.shieldTechLvl = shieldTechLvl; 
    this.employeesNeeded = employeesNeeded; 
    this.description = description; 
    this.imageFilePath = imageFilePath; 
    this.structureNeeded = structureNeeded; 
    this.storageSize = storageSize; 
    this.unitSpeed = unitSpeed; 
    this.attackPower = attackPower; 
    this.weaponTech = weaponTech; 
    this.shipposx = 0; 
    this.shipposz = 0; 
    this.mesh = mesh; 


unit.prototype.setMesh = function (mesh){ 
    this.mesh = mesh; 
    this.mesh.position.x = unit.prototype.getShipPosx(); 
    this.mesh.position.z = unit.prototype.getShipPosz(); 
    this.mesh.position.y = 0; 
    this.mesh = this; 
}; 

unit.prototype.setShipPos = function (posx,posz){ 
    this.shipposx = posx; 
    this.shipposz = posz; 
    //self.position.x =posx; 
    //self.position.z =posz; 
    //self.position.y =0; 
    unit.prototype.setMesh(this.mesh); 
}; 

unit.prototype.getShipPosx = function(){ 
    return this.shipposx; 
}; 

unit.prototype.getShipPosz = function(){ 
    return this.shipposz; 
}; 


//método que define o tamanho do shield inicial. 
unit.prototype.setShieldSize = function(){ 

}; 
//método que altera o armor e shield mediante o damage até à destruição da unidade. 
unit.prototype.setDamage = function(damage) { 
    var armorCheck = false; 
    if (this.shieldSize > 0){ 
     this.shieldSize = this.shieldSize - damage; 
    } 
    else if (this.shieldSize < 0){ 
     this.shieldSize = 0; 
     armorCheck = true; 
    } 
    if (armorCheck === true){ 
     this.armor = this.armor - damage; 
    } 
    else if (this.armor < 0){ 
     this.armor = 0; 
     delete unit; 
     //não esquecer, se houver tempo implementar chamada à explosão da unidade ex: explode(). 
    } 
}; 
//possivel método de explosão. 
unit.prototype.explosion = function(posx,posy){ 
    //carrega uma explosão na posição x e posição y. 
}; 

//método para carregar objeto 3D da unidade. 
unit.prototype.load3D = function(name,imageFileName){ 
    BABYLON.SceneLoader.ImportMesh(name, "Assets/babylonreadyfiles/", imageFileName, scene, function(newMeshes) { 


    newMeshes[0].scaling.x = 0.2; 
    newMeshes[0].scaling.y = 0.2; 
    newMeshes[0].scaling.z = 0.2; 

    unit.prototype.setMesh(newMeshes[0]); 
    //if (selfchecker === 0) { 
    //selfchecker = 1; 
    /*$.get("Communications/getUnit.php", function(data) { 
     //console.log(data); 
     var name = jQuery.parseJSON(data); 

    });*/ 
    /*$.get("Communications/getPosition.php", function(data) { 
     //console.log(data); 
     var pos = jQuery.parseJSON(data); 
     newMeshes[0].position.x = pos.posx; 
     newMeshes[0].position.z = pos.posy; 
     newMeshes[0].position.y = 0; 
    });*/ 

    //}; 


    }); 

}에; this.setMesh(...)

}

+0

.. 그리고 어떤 행이 발생합니까? 분명히 우리는 124 줄의 코드를 살펴보고 정의되지 않은 기능을 찾기를 기대할 수는 없을 것입니다. ** 편집 ** : 실제로 게시 한 코드는'.value' * once *를 참조하지 않습니다. – h2ooooooo

+0

물론입니다. 미안하지만, 내 실수 야. 내가 "unit.prototype.setMesh (this.mesh);를 호출 할 때;" unit.prototype.setShipPos 함수에서. – Saguim

답변

관련 문제