So far, I'm trying to create a 2-Dimensional JSON array to hold a series of shapes inside a series of 'frames'. So far I thought I had it, but I can only push shapes to frame[0]; as soon as I pass it frame[1] I get the error Uncaught TypeError: Cannot read property 'shape' of undefined.
Why can't my browser recognise frame[1] as a potential next storage area for the frame array? Is it something to do with how I've initialised the JSON Array?
Relevant code so far:
function Obj(type, x, y, w, h, r) {
"use strict";
this.type = type || null; //rect, crcl, line, text
this.x = x || null;
this.y = y || null;
this.w = w || null; //used for rect, line
this.h = h || null; //used for rect, line
this.r = r || null; //used only for crcl
}
var keyframes = {
'frame': [{
'shape': []
}]
};
var shape1 = new Obj('rect', 20, 20, 20, 20, 0);
var shape2 = new Obj('crcl', 20, 20, 0, 0, 20);
keyframes.frame[0].shape.push(shape1);
keyframes.frame[1].shape.push(shape2);