如何在ActionScript 3中創建公交時刻表倒計時,我在網上搜索,但主要是爲假期或特定日期倒計時出現。我需要它是經常性的,公交車每30分鐘運行一次。在動作3倒計時
Q
在動作3倒計時
0
A
回答
0
package
{
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
public class countdownTimer extends Sprite
{
private var timer:Timer = new Timer(1000);
private var countdown:Number = 60;
public function countdownTimer():void
{
init();
}
private function init():void
{
timer.start();
timer.addEventListener(TimerEvent.TIMER, action);
}
private function action(e:TimerEvent):void
{
countdown--;
trace(countdown);
}
}
}
它只是基本..希望它會幫助你。
1
我做了一個小的Flash應用程序,給你一個想法,你如何接近公交站牌與倒計時:
schedule.xml:
<?xml version="1.0" encoding="utf-8" ?>
<schedule>
<bus>
<name>1</name>
<times>
<time>1300</time>
<time>1400</time>
<time>1500</time>
<time>1600</time>
<time>1700</time>
</times>
</bus>
<bus>
<name>2</name>
<times>
<time>1300</time>
<time>1400</time>
<time>1500</time>
<time>1600</time>
<time>1700</time>
</times>
</bus>
</schedule>
Main.as(文檔類) :
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.utils.Timer;
[SWF(width="200", height="350", backgroundColor="0xFFFFFF", frameRate="32")]
public class Main extends Sprite
{
private var _scheduleUi:ScheduleUI;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}// end function
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var urlLoader:URLLoader = new URLLoader(new URLRequest("xml/schedule.xml"));
urlLoader.addEventListener(Event.COMPLETE, onUrlLoaderComplete);
}// end function
private function onUrlLoaderComplete(e:Event):void
{
_scheduleUi = new ScheduleUI(XML(URLLoader(e.target).data));
addChild(_scheduleUi);
}// end function
}// end class
}// end package
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
internal class ScheduleUI extends Sprite
{
private var _schedule:Schedule;
private var _scheduleTextField:TextField;
public function ScheduleUI(scheduleXml:XML)
{
_schedule = new Schedule(scheduleXml);
_scheduleTextField = new TextField();
_scheduleTextField.autoSize = TextFieldAutoSize.LEFT;
_scheduleTextField.multiline = true;
addChild(_scheduleTextField);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}// end function
private function onEnterFrame(e:Event):void { updateScheduleTextField() }
private function updateScheduleTextField():void
{
var scheduleString:String = new String();
for each(var bus:Bus in _schedule.getBuses())
{
scheduleString += "BUS: " + bus.name;
for each(var time:Time in bus.getTimes())
{
scheduleString += "\n\n" + "\t" + "Time: " + time + ", Counddown: " + time.getCountDown();
}// end for each
scheduleString += "\n\n";
}// end for each
_scheduleTextField.text = scheduleString;
}// end function
}// end class
internal class Schedule
{
private var _schedule:XML;
public function Schedule(schedule:XML):void
{
_schedule = schedule;
}// end function
public function getBuses():Vector.<Bus>
{
var buses:Vector.<Bus> = new Vector.<Bus>();
for each(var bus:XML in _schedule.bus) buses.push(new Bus(bus));
return buses;
}// end function
}// end function
internal class Bus
{
private var _bus:XML;
public function get name():int { return _bus.name }
public function Bus(bus:XML) { _bus = bus }
public function getTimes():Vector.<Time>
{
var times:Vector.<Time> = new Vector.<Time>();
for each(var time:XML in _bus.times.time) times.push(new Time(time));
return times;
}// end function
}// end class
internal class Time
{
private var _time:XML;
public function Time(time:XML) { _time = time }
public function getCountDown():String
{
var hours:int = _time.toString().substring(0, 2);
var minutes:int = _time.toString().substring(2, 4);
var currentDate:Date = new Date();
var date:Date = new Date();
date.setUTCMilliseconds(0);
date.setUTCSeconds(0);
date.setUTCMinutes(minutes);
date.setUTCHours(hours - 1);
var countDownDate:Date = new Date();
countDownDate.setTime((date.getTime() - currentDate.getTime()))
return (countDownDate.getTime() > 0) ? countDownDate.toTimeString().substring(0, 8) : String(0);
}// end function
public function toString():String { return _time }
}// end class
+0
別擔心我會在更新我的答案時解釋所有課程,但首先我需要運行該應用程序的屏幕截圖並將其添加到答案中。 – Taurayi 2011-05-11 14:21:31
相關問題
- 1. 倒計時時鐘在軌3
- 2. 自動倒計時器和動態倒計時器android
- 3. ActionScript 3 - 定時器/倒數計時器
- 4. PHP:製作倒計時自動更新
- 5. Flash動作腳本倒數計時器
- 6. PHP倒數計時器動作
- 7. jQuery倒計時 - 每日倒計時,還有次要倒計時?
- 8. 倒計時不工作jquery
- 9. GreaseMonkey倒計時不工作?
- 10. 倒計時應用動畫
- 11. 在倒計時計時器中啓動另一個計時器
- 12. JQuery倒計時器不倒計時
- 13. Js倒計時只倒計時一次
- 14. C#timer_Tick()倒計時2步倒計時
- 15. jQuery倒計時不正確倒計時
- 16. 倒計時 - iPhone倒數計時器
- 17. 修復倒計時倒數計時器
- 18. JS倒計時不倒計時
- 19. 倒計時在Javascript
- 20. 倒計時在Python
- 21. 在Qt中製作倒數計時器
- 22. 如何製作3分鐘倒數計時器
- 23. 帶有動作腳本的倒數計時器的隨機開始編號3
- 24. 倒計時倒檔副
- 25. 循環倒數倒計時
- 26. jQuery的動畫不工作(數倒計時/計數)
- 27. Vb.net倒計時
- 28. Scanf倒計時
- 29. 倒計時
- 30. 倒計時Javascript
你有沒有嘗試過自己?張貼你已經做了什麼的一些代碼。你使用TextField嗎?這是非特定的方式。 – DanielB 2011-05-10 15:34:21
請詳細說明。你有沒有試過計時器? – taskinoor 2011-05-10 15:43:22