2011-09-22 2 views
0

내가 비디오에서 진행을 보여줍니다 이벤트 발사가 값 :반복 계수를 제외은

_currentPosition = 3.86 초 _currentPosition = 4.02 초 _currentPosition = 4.16 초 등

내가 노력하고있어 5 초마다 서버에 알림을 보내 진행 상황을 나타냅니다. Math.floor를 사용하여 초를 가장 가까운 정수로 반올림 할 수 있습니다. 그러면 계수를 사용하여 5 초마다 얻을 수 있습니다. 내가 못 보는 것은 5.02, 5.15, 5.36 등이 모두 자격을 얻기 때문에 (예 : 5) 반복을 보내지 않는 방법입니다.

저는 enterframe과 비슷한 빠르게 발사되는 이벤트에서 실행되는 다음과 같은 것을 원합니다. 하지만 ...

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; 

덕분에이 곳을 다시 선언하는 _sentNumber에 대한 테스트를 할 어디에서 어떻게 모르겠어요.

답변

0

거의 다 왔을 것 같습니다. 난 그냥 if 문 내부의 _sentNumber 선언을 넣어 것 :

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; 
    } 
} 
+0

그래, 즉 그것 뿐이다. 감사! – David

+0

왜 * *이 * 작동합니까? int는 기본 데이터 유형입니다. 따라서 var _sentNumber : int를 말하는 것은 var _sentNumber : int = new int()를 말하는 것과 같습니다. 따라서 _sentNumber를 통과 할 때마다 0으로 다시 초기화해야하므로이 코드는 실패합니다. – David

+0

나는 그저 단순함을 위해서 그 위치에 var _sentNumber : int를 넣었다고 생각했다! 예, 함수 선언의 범위를 함수의 범위 밖으로 옮겨서 다시 초기화하지 않도록해야합니다. 나는 그것을 반영하기 위해 나의 대답을 업데이트 할 것이다. – meddlingwithfire

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"); 
    } 
} 
관련 문제