所以总结一下,答案是一个只包含这个的 php 脚本:
<?php
header("Content-Type: text/plain");
print time();
?>
我用来从服务器获取时间的脚本是:
//cut from a larger script
{
loader = new URLLoader();
loader.load(new URLRequest("http://grambogames.net/serverTime.php"));
loader.addEventListener(Event.COMPLETE, onServerTimeLoad);
trace("waiting for time to load");
}
private function onServerTimeLoad(e:Event):void
{
trace("date loaded:", loader.data);
try
{
var num:Number = Number(loader.data) * 1000
dato = new Date(num);
trace("tid & dato synkronisert med server.", dato);
}
catch (e:Error)
{
//the passed date was invalid, lets just use the local system date
dato = new Date();
trace("date did not work, local time used");
txt_error.text = "ERROR! COULD NOT GET TIME FROM SERVER!"
}
if (! dato)
{
//your output from the server isn't formatted in a way flash can convert it
trace("not working, date farmated wrong");
}
}
感谢 LondonDrugs_MediaServices
...我只是希望没有更多的错误出现。