Action Script 3.0으로 주어진 날짜/시간에 작업 (기능)을 실행하도록 예약하는 방법이 있습니까? 나는 schedule(myFunction:Function, dateTime:Date)
과 같은 것을 의미합니다. 감사합니다Action Script 3.0이 포함 된 Cron 작업
1
A
답변
2
본래 그 자체가 아닙니다.
다른 답변에서 설명한대로 SetTimeout은 아마도 가장 쉬운 내기 일 것입니다. 다음과 같이
public class Scheduler {
public var time:Date;
public var action:Function;
public var parameters:Array;
private var checkInterval:Number = NaN;
public function get interval():Number { return checkInterval; };
public function set interval(val:Number):void {
checkInterval = val;
if (schedules && (mainTimer && mainTimer.delay > val)) {
mainTimer.delay = val;
}
}
public function Scheduler(time_:Date, action_:Function, interval_:Number = NaN, parameters_:Array = null):void {
time = time_;
action = action_;
checkInterval = interval_;
parameters = parameters_;
}
//static stuff
private static var mainTimer:Timer;
public static function stop():void {
if (mainTimer) {
mainTimer.stop();
}
}
public static function start():void {
if (mainTimer && !mainTimer.running) {
mainTimer.start();
}
}
public static function get curInterval():Number { return (mainTimer) ? mainTimer.delay : 0; };
private static var scheduleList:Vector.<Scheduler>;
public static function get schedules():Vector.<Scheduler> { return scheduleList; };
/**
* Schedules a function to run at a certain time (with the margin of the interval)
* @param time - what time to run this passed action
* @param action - a function to call between the time passing, and the next interval
* @param interval - how often to check if the time has come, default is 1 second
* @param ... rest - parameters to pass to the action method
* @return
*/
public static function scheduleAction(time:Date, action:Function, interval:Number = NaN, ... rest):Scheduler {
var s:Scheduler = new Scheduler(time, action, interval, rest);
//if already old
if (time.time < new Date().time) {
action.apply(null, rest);
return s;
}
if (!scheduleList) {
scheduleList = new Vector.<Scheduler>();
}
scheduleList.push(s);
if (!mainTimer) {
mainTimer = new Timer(1000);
mainTimer.addEventListener(TimerEvent.TIMER, timerTick);
mainTimer.start();
}
if (!isNaN(interval) && interval < mainTimer.delay) {
mainTimer.delay = interval;
}
return s;
}
private static function timerTick(e:TimerEvent):void {
var tmpDate:Date = new Date();
for (var i:int = scheduleList.length-1; i >= 0;i--){
if (tmpDate.time >= scheduleList[i].time.time) {
scheduleList[i].action.apply(null, scheduleList[i].parameters);
removeSchedule(i);
}
}
checkTimerNeeded();
}
private static function checkTimerNeeded():void {
if (scheduleList && scheduleList.length < 1) {
mainTimer.stop();
mainTimer.removeEventListener(TimerEvent.TIMER, timerTick);
mainTimer = null;
scheduleList = null;
}
}
private static function removeSchedule(index:int):void {
scheduleList.splice(index, 1);
checkTimerNeeded();
}
/**
* Cancels a scheduled item
* @param s - the item to cancel
* @return returns true if the item was scheduled, false if the item wasn't scheduled
*/
public static function cancelSchedule(s:Scheduler):Boolean {
if (scheduleList) {
var index:int = scheduleList.indexOf(s);
if (index > 0) {
removeSchedule(index);
return true;
}
}
return false;
}
public static function status():void {
trace("isRunning:", (mainTimer) ? mainTimer.running : null);
trace("List Length:", scheduleList ? scheduleList.length : null);
}
}
사용 (대신 타이머의 setTimeout을 사용하도록 수정 될 수 있지만 타이머를 선호) : 당신은 당신이 예정 원했던 많은 일을 한 경우에, 여기를 관리 할 수있는 클래스입니다
여기Scheduler.scheduleAction(myDateToRunTheFunction, myFunctionToRun, howOftenToCheckTime, functionParameter1, functionParameter2, functionParameter2);
2
는이 기능을 실행하는 날짜에 걸리는, 그것을 할 수있는 방법입니다 긴 나는 '스케줄러의 구현을 좋아 다음 호출 기능을 실행할에서는 setTimeout
var date:Date = new Date(2012,9,13);
schedule(myFunction,date);
private function myFunction():void
{
trace("Schedule function run");
}
private function schedule(func:Function,date:Date):void
{
var now:Date = new Date();
if (date.time < now.time)
return;
var timetorun:Number = date.time - now.time;
setTimeout(func, timetorun);
}
관련 문제
- 1. soapclient가 PHP에 포함 된 cron 작업 문제
- 2. Wix 3.0이 포함 된 단계별 ngen
- 3. 비동기 서블릿 3.0이 포함 된 GWT requestbuilder
- 4. 3.0이 포함 된 Android 호환성 패키지
- 5. Action Script 3.0의 버튼 수정
- 6. 명명 된 Cron 작업 만들기
- 7. Google Appengine CRON 작업 (spring velocityengineutil 포함)
- 8. Action Script 3 new loader
- 9. Action Script 3에서 Nagle의 알고리즘 비활성화
- 10. KnockoutJS 및 MVC 3.0이 포함 된 중첩 템플릿
- 11. 동적으로 cron 작업 추가
- 12. Action Script 3에 printf와 같은 것이 있습니까?
- 13. Youtube API with Action Script 3
- 14. cron 작업 - 쿼리 데이터베이스는 이메일
- 15. codeigniter의 Cron 작업
- 16. Lync 2010 UCMA 3.0이 포함 된 그룹 추가 C#
- 17. Yii 및 cron 작업
- 18. 포함 된 리소스로 작업
- 19. cron 작업이 포함 된 uwsgi 웹 앱?
- 20. Action Script 3.0에서 레이아웃을 디자인하는 방법은 무엇입니까?
- 21. Action Script 3.0의 표준 클래스의 필터 속성
- 22. addEventListener (Action Script)에서 인수 전달 방법
- 23. Action Script 3에서 XML로 2D 배열 직렬화
- 24. Action Script 3.0의 다음 프레임으로 이동
- 25. 동적으로 변수를 생성하는 방법 Action Script 2.0
- 26. Action Script 3.0 : json 데이터 구문 분석
- 27. Action Script 3.0을 사용한 데이터베이스 액세스
- 28. Action Script 3의 경량 콤보 상자
- 29. Action Script 2.0을 편집하여 이미지 폴더를 순환합니다.
- 30. Action Script 3.0의 변수에 대한 IF 구문
이 방법을 발견 '수업, 나는 시도 해봐! 덕분에 @ LondonDrugs –
어떻게 되었습니까? 이 기능의 장점은 예정된 모든 작업을 일시 중지 할 수 있다는 것입니다 (모달 상자를 방해하지 않으려는 경우), 취소하고 항상 대기열에있는 항목에 액세스 할 수 있습니다. – BadFeelingAboutThis
도움을 주셔서 감사하지만 마침내 나는 해결하고 싶었던 문제를 위해 특별히 Timer 클래스를 사용하여 더 간단한 구현에서 제안을 사용했다. –