[thelist] [JavaScript] way around these global vars?
Tom Dell'Aringa
pixelmech at yahoo.com
Tue Feb 7 11:03:19 CST 2006
<grumble> All right, bad habits and all that. </grumble> ;) I think I have it except I'm making
some kind of syntax error possibly, as the setTimeout() does not recognize the showHit() function:
stickystate = {
currentBtn:null,
showHit:function(btn)
{
if(!btn)
{
var newImg = this.currentBtn.style.backgroundImage;
newImg = newImg.replace("_on", "");
this.currentBtn.style.backgroundImage = "url(/images/" +newImg+ ")";
return;
}
else
{
var urlArray = btn.style.backgroundImage.split("/");
var img = urlArray[urlArray.length -1].replace(".gif)", "");
var on = "url(/images/" + img + "_on" + ".gif)";
this.currentBtn = btn;
btn.style.backgroundImage = on;
setTimeout("this.showHit()", 500)
}
}
}
I've tried stickystate.showHit(), that doesn't do it either (seems like it would be the same
thing). How do I recursively call this method from within?
--- Christian Heilmann <codepo8 at gmail.com> wrote:
> I am more worried about the state of the other code :-) The object
> literal is a wonderful idea as it does keep everything together that
> should be together.
>
> Why do you need two variables anyways? All you need is the current
> object, then you read the backgroundImage and check if it contains
> _on.gif or not and replace it with .gif and vice versa.
http://www.pixelmech.com/
http://www.crossandthrone.com/
Professor Rumford: 'But I still don't understand about hyperspace.'
The Doctor: 'Well, who does?'
K9: 'I do.'
Doctor: 'Shut up, K9!'
More information about the thelist
mailing list