Here's a good one!
You create an object with a method, like so:
function myobj_looper() {
. . .
. . .
timer_id = setTimeout( "myobj_looper()", 1000 );
}
function myobj_start() {
this.looper();
}
function myobj() {
. . .
. . .
this.start = myobj_start;
this.looper = myobj_looper;
}
Now, you instantiate an object, and start the looper, like so:
someobj = new myobj();
someobj->start();
The start() method uses setTimeout() to call the looper routine. The
looper routine uses setTimeout(), to call itself every second.
Only trouble is, it doesn't work.
I've never tried using setTimeout() within an object method before. I've tried booth of these:
timer_id = setTimeout( "myobj_looper()", 1000 );
timer_id = setTimeout( "this.looper()", 1000 );
timer_id = this.setTimeout( "looper()", 1000 );
neither of which seem to work at all. Neither one generates any errors,
but looper() doesn't seem to run, other than the first time when called initially from start(). Since setTimeout() returns an "opaque value" for timer_id, and there doesn't seem to be any way of determining the success
of the setTimeout() call, I am only *assuming* that it is failing, but I can't see any other reasonable explanation.
So anybody got any suggestions on the proper way to call setTimeout() with an object method as the code argument?
sorry for top posting...
ugly, but here goes...
Presuming this is meant for a browser...
sorry for top posting...
ugly, but here goes...
Presuming this is meant for a browser...
Ok, thanks! I'll have a go at it in a minute.
Ok, thanks! I'll have a go at it in a minute.
yeah, it gets kind of ugly, put a little check in to be able to stop
and restart, the objectID is mainly for being able to assign/reference
from the window object... intervals & timeouts in JS/browser are a bit
of a real pain... at least doing a lock-like setting is relatively easy
as js is all called in the same thread (not always in order) though.
What I was NOT able to achieve was the use of a string objectID...
It also works with explicitly assigned numeric values for this.objectID (I tried my telephone number and that worked fine). What I was NOT able to achieve was the use of a string objectID -- which would have been
convenient for various reasons. I tried
What I was NOT able to achieve was the use of a string objectID...
Heh! Just tried this again, and of course, it worked fine. I guess last time I tried it I was too cross-eyed weary to see whatever obvious typo I included that made it fail.
Now if only I could find a way to determine the name of the instance of a particular class instance....
I dunno how you do it, but as soon as I tell you about a piece of code
that *will* not work, no matter what I do... it immediately starts working without my having to do anything to make it!
The startit() and stopit() methods now work fine. And I haven't changed a thing!
Oh well...
Now if only I could find a way to determine the name of the instance of a particular class instance....
LOL, wouldn't that be nice...
I've done this with tree (parent/child) type objects, by passing the
"name" assigned as part of the constructor...
What I've been doing is creating and manipulating PHP objects which do the server-side grunt-work (accessing MySQL, or whatever), and then I do something like $phpobj->emit_JS(); which writes the apropriate JS to
create the client-side JS objects. This can emit calls to constructors
with very complicated argument lists, or a simpler constructor followed by
a series of calls to additional methods to set other properties of the JS objects. I'm passing the objectID to the PHP constructor, and emit_JS() propagates the same objectID when it generates the JS constructor.
I'm tweaking the CSS as well, but I'm experimenting with generating object specific stile blocks, generating inline style-'' attributes to the HTML elements in question, or using a pre-defined class and then issuing JS commands to alter the CSS for specific elements as needed. I've yet to decide which approach I like best.
Isn't there already a JSON module/library for php?
You may want to give a look at the following.. :)
JavaScript Object Notation (JSON): http://www.json.org/
JavaScript OOP - http://phrogz.net/JS/Classes/OOPinJS.html
Prototype - http://prototype.conio.net/
Behavior - http://bennolan.com/behaviour/
Sysop: | MCMLXXIX |
---|---|
Location: | Prospect, CT |
Users: | 325 |
Nodes: | 10 (0 / 10) |
Uptime: | 141:36:20 |
Calls: | 506 |
Messages: | 219686 |