I am wondering why I cannot retrieve the value in the alert function. I know the 'mainObj' is being created as I can test with an alert within the object constructor. but I can not access the child object properties. Can someone explain what I'm doing wrong? Here is the code:
//used as a global
var theOBJ;
//child objects
function objChild(n,o,bgc){
this.name = n;
this.orientation = o;
this.backgroundcolor = bgc;
}
//the Main Object
function objMain(n,o,bgc,ns){
this.name = n;
this.numsides = ns;
if(this.numsides>2||this.numsides<1){
alert("Number of sides are incorrect, setting to '1'");
numsides=1;
}
child1 = new objChild(n+"_child1",o,bgc);
}
function createNewObject(n){
//create a new Object
theOBJ = new objMain(n,"landscape","",3);
alert(theOBJ.child1.name);
}