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.
-- 
Nick W (nickw77 at shaw.ca)
Registered Linux User #324288 (http://counter.li.org)
MSN Messenger: [EMAIL PROTECTED]
Yahoo: foolish_gambit
ICQ: 303276221
It's not our fault, we're outnumbered by stupid people ten to one.

_______________________________________________
clug-talk mailing list
[EMAIL PROTECTED]
http://clug.ca/mailman/listinfo/clug-talk_clug.ca

Reply via email to