Like I was saying in this post I started working on this cool little script in JavaScript that moves HTML objects around on a website, a really cool script overall for all sorts of floating message effects....
And after I got home from work a little after 7:00 AM this morning I have been working on giving it classes to be smart... actually, to move more than one HTML object around in a totally customizable fashion.
However, when doing such I ran into a little problem... apparently a problem a lot of people have with Classes or Objects and the setInterval()
method...
Especially when you try to do this:
setInterval("ObjectName.methodName()", this.pinginterval);
Which made making my script work with classes a whole lot harder than I thought it was going to be!
And Nothing Here Is Or Was Helpful!
So I found my own super-Genius - with a capital G - workaround!!!
Instead of doing this ...
setInterval("ObjectName.methodName()", this.pinginterval);
... I did this ...
setInterval("functionName('"+ObjectName+"')", this.pinginterval);
This works for me because my Classes or Objects are in an array:
var Objects = new Array('ObjectName1', 'ObjectName2', ... 'ObjectNameN');
So as long as I kept passing the ObjectName
as a parameter to each subsequent function I could then call anything I want from the Class or Object simply by using:
Objects[ObjectName].Paramater
What tripped me up and had me pulling my hair out trying to figure out what was wrong with a particular line I typed, was a simple syntax error - when I typed:
setInterval("functionName("+ObjectName+")", this.pinginterval);
Instead of typing:
setInterval("functionName('"+ObjectName+"')", this.pinginterval);
Did you see it?
I forgot to include the single quotes around the function's parameter...
So basically when the line I typed was processed by the browser it would have seen functionName(strObjectName);
instead of functionName('strObjectName');
as it should be in proper syntax.....
A stupid mistake that sent me hunting and trying to figure out what was wrong with it for about a half hour!
And now after I finished the script the time is 3:30 PM
I've been working on it for about 7½ hours. (Once you factor in eating and watching TV for a bit as I pulled my hair out to find a solution!!)
This all just goes to show one thing....
I AM A GENIUS!!
And that's final!
No comments:
Post a Comment