[英]Can anyone tell me why i am getting the error 'Cannot read property 'value' of undefined'? P5.JS
I am coding a drawing app in which i am using constructor functions, my code is to try to get a hexagon to appear as a drawing tool.我正在编写一个使用构造函数的绘图应用程序,我的代码是尝试让六边形显示为绘图工具。 My issue is when i was trying to link it to another constructor function, it gives me the error
我的问题是当我试图将它链接到另一个构造函数 function 时,它给了我错误
Hexagon.js:27 Uncaught TypeError: Cannot read property 'value' of undefined
at HexagonTool.draw (Hexagon.js:27)
at draw (sketch.js:53)
at e.d.redraw (p5.min.js:32)
at e.<anonymous> (p5.min.js:31)
Does.value() not work as a constructor function? .value() 不能作为构造函数 function 工作吗? my code is split so all constructor functions are separate which link into a sketch and html file, i can post more code of other areas to help figure it out if need be.
我的代码被拆分,因此所有构造函数都是分开的,它们链接到草图和 html 文件中,如果需要,我可以发布更多其他区域的代码以帮助弄清楚。 The code is below:
代码如下:
function HexagonTool() {
//set an icon and a name for the object
this.icon = "assets/shapes.jpg";
this.name = "shapes";
var Hexagon;
var HexagonSize;
var HexagonSizeSlider;
var nHexagonSlider;
function preload() {
Hexagon = loadImage('assets/Hexagon.png');
}
function setup() {
HexagonSizeSlider = createSlider(5, 60, 20);
HexagonSizeSlider.parent("#sizeOfHexagonControl");
nHexagonSlider = createSlider(1, 25, 5);
nHexagonSlider.parent("#numberOfHexagonsControl");
}
this.draw = function() {
if (mouseIsPressed) {
for (var i = 0; i < nHexagonSlider.value(); i++) {
var HexagonSize = HexagonSizeSlider.value();
var HexagonX = random((mouseX - HexagonSize / 2) - 25, (mouseX - HexagonSize / 2) + 25);
var HexagonY = random((mouseY - HexagonSize / 2) - 25, (mouseY - HexagonSize / 2) + 25);
image(Hexagon, HexagonX, HexagonY, HexagonSize,
HexagonSize);
}
}
}
}
I am looking at it, and this is after a few hours of trying to get it to work, i had two copies of preload and, removing the setup in the code above solved it我正在看它,这是在尝试让它工作几个小时之后,我有两个预加载副本,并且删除上面代码中的设置解决了它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.