Is there a problem with doing:
document.onmousemove = this.getMouseXY;
Before a do the line above it knows exactly what object "this" refers to. I then calls the function fine (I've declared them as methods of the function). But then within the method getMouseXY the alert doesn't remember what object I was on, i.e. displays [Object] instead of [object Object]. Any ideas?
I guess I could store the object ID in a variable before calling the function, and then pick it up again from within the getMouseXY - it's just that solution is a bit untidy, and it would be easier to follow if I could just use the "this".
function startCheckMousePos()
{
// Start detecting where the mouse is.
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Eve
nt.MOUSEMO
VE);
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = this.getMouseXY;
}
function stopCheckMousePos()
{
// Stop detecting where the mouse is.
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.releaseEvents(Eve
nt.MOUSEMO
VE);
document.onmousemove = null;
}
function getMouseXY(e)
{
// Main function to retrieve mouse x-y position of the mouse.
// Temporary variables to hold mouse x-y positions.
var tempX = 0;
var tempY = 0;
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
if (IE)
{
// grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else
{
// grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
// catch possible negative values in NS4
if (tempX < 0) {tempX = 0}
if (tempY < 0) {tempY = 0}
// show the position values in the form named Show
// in the text fields named MouseX and MouseY
document.Show.MouseX.value
= tempX;
document.Show.MouseY.value
= tempY;
if (tempX == 100)
{
//alert(document.getElemen
tById(this
.knowdeID)
.style.lef
t);
alert(this.knowdeID); // Seems to have forgotten which object I am on!
}
return true;
}