<html> <head> <script>
forest = new my_forest();
function my_forest() {
this.type = "rainforest";
} function start() {
alert("What? " + forest.type);
}
</script></head> <body onload="start()"> <p>Test For Nick</p> </body> </html>
I suggest we take it off list...
pvdwATcriticalcontrol DOT com
Pete
Nick W wrote:
Sorry for the OT post but this makes no sense and every source I read tells me this should work.
I have a stupid problem with a script Im writing. I have an object which contains an array of objects, which contain image objects. I set the onmouseover property of the images to run a function which needs data from one of the outermost object's properties. The said function can see the object, but not its properties. OK thats clear as mud, let me try a simplified example...
<begin lame example>
function Forest() { this.type = 'rainforest'; trees = new Array();
this.MakeTrees = MakeTrees; }
function MakeTrees() { for(i = 0; i < 1000; i++)//make 1000 trees { this.trees[i] = new Tree(); } }
function Tree() { this.img = new Image(); //pretend I set the this.img properties here... this.img.onmouseover = TreeInfo; }
function TreeInfo() { alert(typeof(my_forest)); alert('This tree is in a ' + my_forest.type); }
my_forest = new Forest(); my_forest.MakeTrees(); <end lame example>
When you mouseover a tree, the first alert in TreeInfo() will tell you my_forest is an object, but the 2nd one will spit out "This tree is in a undefined". Why??
Note, the above code was written very quickly and is probably unuseable, but it serves its purpose as a lame example.
Its obviously some sort of scope issue with Java I dont get. AFAIK, my_forest should be global in this case. My other question is in MakeTrees() does the 'this' in 'this.trees[i]' point to my_forest? Of course the whole thing could be FUBAR....
tks.
_______________________________________________ clug-talk mailing list [EMAIL PROTECTED] http://clug.ca/mailman/listinfo/clug-talk_clug.ca

