I am running into a problem where the functions within a movie are not waiting
for the variables to be pulled from my service. Therefore I get an undefined
error on my text box where the time(result of my function) should be displayed.
Thank you in advance for your time.
Here is my code.
Within the root (frame 1) I have the following code:
import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
// create RelayResponder to specify result handling methods
var myResponder:RelayResponder = new
RelayResponder(this,"GetNISTTime_Result","GetNISTTime_Fault");
// establish gateway and create a Service object to refer to the service
var ptService:Service = new Service(
"http://192.168.2.224/flashservices/gateway",
null,
"ptFlashComService.adapter",
null,
myResponder );
_root.newclock.clk_loaded = "false";
_root.newclock.clk_hours = 2;
trace("not defined yet");
// call service function
var temp_pcclock:PendingCall = ptService.GetNISTTime();
// GetNISTTime_Result and GetNISTTime_Fault are result/fault handlers
function GetNISTTime_Result (re:ResultEvent):Void {
trace("Pull success - " + re.result.SUCCESS);
_root.newclock.clk_success = re.result.SUCCESS;
_root.newclock.clk_hours = re.result.HOURS;
_root.newclock.clk_mins = re.result.MINS;
_root.newclock.clk_secs = re.result.SECS;
_root.newclock.clk_dayof = re.result.DAYOF;
_root.newclock.clk_mon = re.result.MON;
_root.newclock.clk_date = re.result.DATE;
_root.newclock.clk_loaded = "true";
trace("is defined");
}
function GetNISTTime_Fault (fe:FaultEvent):Void {
trace("NISTTimeCallFailed-" + fe.fault.description);
}
[B]Then I have a movie called newclock that contains 3 frames and a text box
that will display the time.
Frame 1 [/B]
//constructor for clock object
function Clock(h, m, s, ms)
{
this.hours = h;
this.minutes = m;
this.seconds = s;
this.millisecs = ms;
this.endTimer = getTimer()+(ms+s*1000+m*60000+h*3600000);
this.startTimer = -this.endTimer;
//explicitly set clock to a certain time
this.setTime = function (h, m, s, ms)
{
this.hours = h;
this.minutes = m;
this.seconds = s;
this.millisecs = ms;
this.endTimer = getTimer()+(ms+s*1000+m*60000+h*3600000);
this.startTimer = -endTimer;
}
//update clock object with the current time
//direction: forward = true, backwards = false
this.updateTime = function(direction)
{
millisecs = (direction ? getTimer()-this.startTimer :
this.endTimer-getTimer());
this.hours = (millisecs-(millisecs=(millisecs%3600000)))/3600000;
this.minutes = (millisecs-(millisecs=(millisecs%60000)))/60000;
this.seconds = (millisecs-(millisecs=(millisecs%1000)))/1000;
this.millisecs = substring(millisecs, 1, 2);
}
//returns the clock object as a formatted string
this.displayTime = function()
{
hours = this.hours%13; // Allows time to reach the 13th hour, if not
clock rest at 12:00:00
minutes = (this.minutes<10 ? "0" : "")+this.minutes;
seconds = (this.seconds<10 ? "0" : "")+this.seconds;
millisecs = (this.millisecs<10 ? "0" : "")+this.millisecs;
// Forces the clock upon reset to change hour to start at 1
if (hours == 0) {hours=1;}
return hours+":"+minutes+":"+seconds; //+"."+millisecs;
}
//add to the time on the clock
this.addTime = function(h, m, s, ms)
{
this.endTimer += (ms+s*1000+m*60000+h*3600000);
this.startTimer -= (ms+s*1000+m*60000+h*3600000);
updateTime(Clock, true);
}
//subtract from the time on the clock
this.subtractTime = function(h, m, s, ms)
{
this.addTime(-h, -m, -s, -ms);
}
}
_root.newclock.standardClock = new Clock(clk_hours,clk_mins,clk_secs,0);
[B]Frame 2[/B]
//update times
standardClock.updateTime(true) //true to show passage of time
//display times
//trace("Standard: "+standardClock.displayTime())
var newclock = standardClock.displayTime();
[B]Frame 3[/B]
gotoAndPlay(3);
SincityViper - 16 Jun 2006 19:47 GMT
Solved View the answer here. It is a clock that does not use the clients system
or loadvars to aviod the caching issue.
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=288&threadid=
1163571&enterthread=y