Struggling to create a 2D array of video objects. It works fine with a regular array, but throws an error when attempting to make it 2D - Uncaught TypeError: Cannot read property 'tv' of undefined. The problem seems to be in this line of code: tvObjArray.push(new NewTvObj(createVideo(videoFiles[i][j]), false, 0, 0));
Snippet:
var tvObjArray = [[],[]];
var videoFiles = [
["videos/cityDream.mp4", "videos/cityDream.mp4"],
["videos/cityDream.mp4", "videos/cityDream.mp4"]
];
function setup() {
createCanvas(1000, 576);
// creating new tv object for each screen
for (var i = 0; i < videoFiles.length; i++) {
for (var j = 0; j < videoFiles[i].length; j++) {
tvObjArray.push(
new NewTvObj(createVideo(videoFiles[i][j]), false, 0, 0));
tvObjArray[i][j].tv.loop();
tvObjArray[i][j].tv.hide();
tvObjArray[i][j].tv.pause();
}
}
}
function NewTvObj(tvObj, playingBool, xposVal, yposVal) {
this.tv = tvObj;
this.playing = playingBool;
this.xpos = xposVal;
this.ypos = yposVal;
}
function draw() {
// placing tvs on building
for (var i = 0; i < videoFiles.length; i++) {
for (var j = 0; j < videoFiles[i].length; j++) {
image(tvObjArray[i][j].tv, tvObjArray[i][j].xpos + i * 320,
tvObjArray[i][j].ypos + j * 200);
}
drawSprites();
}
}