PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/test/TestTime.hx

http://github.com/adamb/casahx
Haxe | 80 lines | 61 code | 19 blank | 0 comment | 0 complexity | 326a36b09aa6cc4699b7aed450726ed4 MD5 | raw file
  1. package test;
  2. import flash.display.Sprite;
  3. import flash.events.Event;
  4. import org.casalib.events.InactivityEvent;
  5. import org.casalib.time.EnterFrame;
  6. import org.casalib.time.FrameDelay;
  7. import org.casalib.time.FrameTime;
  8. import org.casalib.time.FrameTimeStopwatch;
  9. import org.casalib.time.Inactivity;
  10. import org.casalib.time.Interval;
  11. import org.casalib.time.Sequence;
  12. import org.casalib.time.Stopwatch;
  13. import org.casalib.util.StageReference;
  14. class TestTime extends Sprite {
  15. var enterFrame:Sprite;
  16. public function new(){
  17. super();
  18. StageReference.setStage(flash.Lib.current.stage);
  19. var stopwatch:Stopwatch = new Stopwatch();
  20. stopwatch.start();
  21. enterFrame = new Sprite();
  22. enterFrame.graphics.beginFill(0,1);
  23. enterFrame.graphics.drawRect(0,0,10,10);
  24. this.addChild(enterFrame);
  25. EnterFrame.getInstance().addEventListener(Event.ENTER_FRAME, onEnterFrame);
  26. var fd = new FrameDelay(onFrameDelay,30,["passed 30 frames"]);
  27. fd.start();
  28. var ina = new Inactivity(1000);
  29. ina.addEventListener(InactivityEvent.INACTIVE,onInactive);
  30. ina.addEventListener(InactivityEvent.ACTIVATED,onActive);
  31. ina.start();
  32. Interval.setTimeout(function(msg:String):Void{
  33. trace(msg);
  34. },5000,["interval 500 passed"]).start();
  35. var s = new Sequence();
  36. s.addTask(function(){trace("Sequence 1");});
  37. s.addTask(function(){trace("Sequence 2");});
  38. s.addTask(function(){trace("Sequence 3...");});
  39. s.addTask(function(){trace("Sequence 4");},500);
  40. s.start();
  41. trace("stopwatch" + stopwatch.time);
  42. }
  43. function onEnterFrame(e:Event):Void {
  44. enterFrame.visible = !enterFrame.visible;
  45. }
  46. function onFrameDelay(msg:String):Void {
  47. trace(msg);
  48. trace(FrameTime.getInstance().time);
  49. }
  50. function onInactive(e:InactivityEvent):Void {
  51. trace("you've been inactive for " + e.milliseconds);
  52. }
  53. function onActive(e:InactivityEvent):Void {
  54. trace("you're active again");
  55. }
  56. static public function main():Void {
  57. neash.Lib.Init("Test",400,300);
  58. flash.Lib.current.addChild(new TestTime());
  59. neash.Lib.Run();
  60. }
  61. }