Forum Moderators: open
For ease of development, pageLoad is called in <body onload="javascript:pageLoad();">. It creates the instances. The changeImage is called on rollout. Obviously, the first call is fine, but as with other people whom have setTimeout problems, the properties of the object are dropped, even though no errors are given.
[pre]function pageLoad() {
link1 = new linkClass('home_link1',null,0,false);
link2 = new linkClass('home_link2',null,0,false);
//link1.msg();
}[/pre] [pre]function linkClass(objId, obj, pos, stop) {
this.obj = obj!=null?obj:getObjById(objId);
this.objId = objId;
this.pos = pos;
this.stop = stop;
this.changeImage = changeImage;
this.highlight = highlight;
this.msg = function(){alert(
"this: " + this + "\n" +
"objId: " + this.objId + "\n" +
"obj: " + this.obj + "\n" +
"pos: " + this.pos + "\n" +
"stop: " + this.stop + "\n");}
}[/pre] [pre] function changeImage() {
with (this) {
//msg();
if (typeof obj == 'undefined') getObjById(objId);
if (typeof pos == 'undefined') pos = -72;
if (!stop) {
if (pos > -288) {
obj.style.background = "#000 url(Menu_Home.png) no-repeat " + pos + "px 0;";
pos -= 72;
window.setTimeout(this.changeImage,275);
}
} else {
obj.style.background = "#000 url(Menu_Home.png) no-repeat 0px 0;";
}
}
}[/pre] Thank you,
vol7ron
[edited by: vol7ron at 4:38 pm (utc) on Mar. 3, 2008]
[pre]window.setTimeout(function (){changeImage()},275);[/pre] I assume making changeImage() and highlight() prototypes would be best on memory - I think they would still have the same functionality. I also think using clearTimeout in combination with the "stop" boolean might help free resources faster.
I'm curious if there was a more efficient way to delay something other than using setTimeout/setInterval.
Thank you,
vol7ron