|
Home > Archive > Macromedia Flash Server > April 2005 > Client-Side NetConnection.call inside a setInterval
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Client-Side NetConnection.call inside a setInterval
|
|
| R.SleepOver 2005-04-07, 5:55 pm |
| Hi,
I'm having a hard-time understanding a problem in one a my application.
I'm trying to build a sort of "fcs timer" : a client plays the role of a
"chrono master" and starts a timer.
One of my approach is the simplest one (yet, quite costly regarding the
bandwith) : the "chrono master" keeps sending, every few seconds, its
local time to the other clients after having "started" the timer.
Each client can then update the timer value according to the start time
and the difference between "master" time and local time.
To do so, I simply use a shared object, which I update every N seconds
by a remote call from the "master".
The problem is that the call seems never to be made.
I don't see the "trace" in the Live Log, and I don't see the call in the
NetConnection Debugger.
I read there were some problem with setInterval and FCS, but isn't it
when setInterval is used in SSAS ?
Below are excerpts of my code.
Thanks for any hint.
--------------- Master Client Side --------------------------
TimerClass.prototype.sendAndUpdateTime = function() {
var reference_time = new Date();
reference_time = reference_time + 0; // thought that
NetConnection.call wouldn't like a "fresh Date" as parameter ...
trace("updating time:"+reference_time);
this.nc.call(this.prefix + "updateTimer", null, reference_time);
};
TimerClass.prototype.timer_start = function() {
trace("I want to start timer");
this.starttime = new Date();
this.local_time_interval = setInterval(this.sendAndUpdateTime, 2000);
this.nc.call(this.prefix + "startTimer", null, this.startTime);
};
---------------- Server Side --------------------------------
FCSTimer.prototype.updateTimer = function(client, newTime) {
trace("updating time");
this.timer_so.setProperty("timer_currenttime", newTime);
}
---------------"Client" Client Side --------------------------
[...]
this.so.onSync = function(list) {
trace("onSync");
if (this.data.timer_status == "started") {
....
}
this.owner.local_timer_update(this.data.timer_currenttime);
};
TimerClass.prototype.local_timer_update = function(masterTime) {
trace("master is updating time:"+masterTime);
if (masterTime > 0) {
var tempDate = new Date();
this.local_diff_time = tempDate - masterTime;
trace("diff :"+this.local_diff_time);
}
};
------------------------------------------------------------
=-----------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=-----------------------------------------------------------
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm
| |
| Nick Gerig 2005-04-07, 5:55 pm |
| setInterval(this.sendAndUpdateTime, 2000);
should be:
setInterval(this,"sendAndUpdateTime", 2000);
cheers
Nick
R.SleepOver wrote:
> Hi,
>
> I'm having a hard-time understanding a problem in one a my application.
> I'm trying to build a sort of "fcs timer" : a client plays the role of
> a "chrono master" and starts a timer.
> One of my approach is the simplest one (yet, quite costly regarding
> the bandwith) : the "chrono master" keeps sending, every few seconds,
> its local time to the other clients after having "started" the timer.
> Each client can then update the timer value according to the start
> time and the difference between "master" time and local time.
>
> To do so, I simply use a shared object, which I update every N seconds
> by a remote call from the "master".
> The problem is that the call seems never to be made.
> I don't see the "trace" in the Live Log, and I don't see the call in
> the NetConnection Debugger.
>
> I read there were some problem with setInterval and FCS, but isn't it
> when setInterval is used in SSAS ?
>
> Below are excerpts of my code.
> Thanks for any hint.
>
> --------------- Master Client Side --------------------------
> TimerClass.prototype.sendAndUpdateTime = function() {
> var reference_time = new Date();
> reference_time = reference_time + 0; // thought that
> NetConnection.call wouldn't like a "fresh Date" as parameter ...
> trace("updating time:"+reference_time);
> this.nc.call(this.prefix + "updateTimer", null, reference_time);
> };
> TimerClass.prototype.timer_start = function() {
> trace("I want to start timer");
> this.starttime = new Date();
> this.local_time_interval = setInterval(this.sendAndUpdateTime, 2000);
> this.nc.call(this.prefix + "startTimer", null, this.startTime);
> };
> ---------------- Server Side --------------------------------
> FCSTimer.prototype.updateTimer = function(client, newTime) {
> trace("updating time");
> this.timer_so.setProperty("timer_currenttime", newTime);
> }
> ---------------"Client" Client Side --------------------------
> [...]
> this.so.onSync = function(list) {
> trace("onSync");
> if (this.data.timer_status == "started") {
> ....
> }
> this.owner.local_timer_update(this.data.timer_currenttime);
> };
>
> TimerClass.prototype.local_timer_update = function(masterTime) {
> trace("master is updating time:"+masterTime);
> if (masterTime > 0) {
> var tempDate = new Date();
> this.local_diff_time = tempDate - masterTime;
> trace("diff :"+this.local_diff_time);
> }
> };
> ------------------------------------------------------------
>
>
> =-----------------------------------------------------------
> Supported by Fig Leaf Software - http://www.figleaf.com
> =-----------------------------------------------------------
>
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcomm
>
>
=-----------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=-----------------------------------------------------------
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm
|
|
|
|
|