Friday, October 5, 2007

Genius Work-Around

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!

Permalink/TrackBack:
http://bvanscoter.blogspot.com/2007/10/genius-work-around.html

No comments:

 

pages

legal information

privacy policy

We respect your privacy and promise to never sell, barter, share or rent your information to any unauthorized third party. By providing your contact information you are also requesting and agreeing to receive important information about future events. (You may unsubscribe at any time.)
view full privacy policy here

certification of authenticity

I certify that the information contained on this site is true and complete to the best of my knowledge and understanding, any discrepencies will be governed by the terms of use.

terms of use

Everything we provide is provided "as is" including but not limited to the implied warranties of merchantability or fitness for a particular purpose, without any promise or guarantee of earnings. All forward looking statements on any of our materials are intended as an expression our opinion and will not responsible for any incidental or consequential damages from your actions.
view official terms of use