Question
Animate HTML5 Canvas/Javascript, help understanding addChild and dot notation
Hello,
I have tried reading up on addChild, and I don't understand how to add objects to parent objects and refer to them. For instance, if I make a Container, add a Box, then add a Triangle to the Box, I want to rotate the Triangle -- but, I don't understand how to reference the Triangle. I would appreciate any explanation of addChild to help clarify this. Thank you!
// Create a box and triangle from the library
var box = new lib.Box();
var triangle = new lib.Triangle();
// Create container1 and add the box and triangle
var container1 = new createjs.Container();
this.addChild(container1);
container1.x = container1.y = 50;
container1.addChild(box);
container1.box.addChild(triangle); // ERROR: Cannot read property 'addChild' of undefined
container1.box.triangle.rotation = 30; // Why can't I rotate the triangle this way?
// Create container2 and add the box and triangle
var container2 = new createjs.Container();
this.addChild(container2);
container2.x = container2.y = 250;
container2.addChild(box);
container2.box.addChild(triangle); // ERROR: Cannot read property 'addChild' of undefined
container2.box.triangle.rotation = 60; // Why can't I rotate the triangle this way?
