我有一个事件触发,显示视频中的进展:
_currentPosition = 3.86秒 _currentPosition = 4.02秒 _currentPosition = 4.16秒 等
我要做的是每五秒向服务器发送一次通知,以指示进度。我可以使用Math.floor将秒数舍入到最接近的整数。然后我可以使用模数来获得每五秒钟。我没有看到的是如何不发送重复(例如)5,因为5.02,5.15,5.36等都将符合条件。
我想要类似下面的东西,它在快速触发的事件中执行,类似于enterframe。但我不知道如何或在哪里为_sentNumber进行测试,在哪里声明它,在哪里重置它......
var _sentNumber:int;
//_currentPosition is the same as current time, i.e. 5.01, 5.15, etc.
var _floorPosition:int = Math.floor(_currentPosition); //returns 5
if(_floorPosition % 5 == 0) //every five seconds, but this should only happen
// once for each multiple of 5.
{
if(_floorPosition != _sentNumber) //something like this?
{
sendVariablesToServer("video_progress");
}
_sentNumber = _floorPosition;
感谢。
答案 0 :(得分:0)
看起来你几乎就在那里。我只是将_sentNumber声明放在if语句中:
var _sentNumber:int = 0;
private function onUpdate(...args:Array):void // or whatever your method signature is that handles the update
{
//_currentPosition is the same as current time, i.e. 5.01, 5.15, etc.
var _floorPosition:int = Math.floor(_currentPosition); //returns 5
if(_floorPosition % 5 == 0 && _floorPosition != _sentNumber) //every five seconds, but this should only happen once for each multiple of 5.
{
sendVariablesToServer("video_progress");
_sentNumber = _floorPosition;
}
}
答案 1 :(得分:0)
private var storedTime:Number = 0;
private function testTime( ):void{
//_currentPosition is the same as current time, i.e. 5.01, 5.15, etc.
if( _currentPosition-5 > storedTime ){
storedTime = _currentPosition
sendVariablesToServer("video_progress");
}
}