PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/haxe/projects/hxs/src/hxsTest/Flash.hx

http://github.com/Fintan/TouchMyPixelHx
Haxe | 115 lines | 70 code | 25 blank | 20 comment | 0 complexity | db9629a420337d843ffab2b395f76216 MD5 | raw file
  1. /**
  2. * HXS - Haxe Signals Library
  3. * @author Tony Polinelli
  4. */
  5. package hxsTest;
  6. import hxs.core.Info;
  7. import hxs.Signal;
  8. import hxs.Signal1;
  9. import hxs.Signal2;
  10. import hxs.Signal3;
  11. import hxs.Signal4;
  12. import hxs.Signal5;
  13. import flash.display.Sprite;
  14. import flash.events.Event;
  15. import flash.events.MouseEvent;
  16. import flash.Lib;
  17. import flash.text.TextField;
  18. import hxs.extras.AS3Signal;
  19. using hxs.shortcuts.as3.Common;
  20. class Flash extends Sprite
  21. {
  22. /*
  23. Comment / uncomment the examples to view each example
  24. */
  25. public function new()
  26. {
  27. super();
  28. Lib.current.addChild(this);
  29. //testAS3();
  30. testAS3Shortcuts();
  31. }
  32. /*
  33. An AS3 event expects to be bound to a listener which expects 1 argument (the native flash event). it is a simple way to use Signal style events with Native Flash events.
  34. */
  35. public function testAS3()
  36. {
  37. var box = new Box(0xffff00);
  38. addChild(box);
  39. var onClick = new AS3Signal(box, MouseEvent.CLICK);
  40. onClick.add(function(e){
  41. trace("clicked");
  42. });
  43. }
  44. /*
  45. Signals can be injected to InteractiveObjects via the 'using' feature. This makes for very concise code.
  46. */
  47. public function testAS3Shortcuts()
  48. {
  49. var box = new Box(0xff0000);
  50. box.x = 200;
  51. addChild(box);
  52. box.onClick().add(function(e) {
  53. trace("onClick");
  54. });
  55. box.onRollOver().add(function(e) {
  56. trace("onRollOver");
  57. });
  58. box.onRollOut().add(function(e) {
  59. trace("onRollOut");
  60. });
  61. box.onMouseDown().add(function(e) {
  62. trace("onMouseDown");
  63. });
  64. box.onMouseUp().add(function(e) {
  65. trace("onMouseUp");
  66. });
  67. box.onReleaseOutside().add(function(e) {
  68. trace("** onReleaseOutside ** (HELL YEAH!)");
  69. });
  70. }
  71. }
  72. class Box extends flash.display.Sprite
  73. {
  74. public function new(color:Int)
  75. {
  76. super();
  77. graphics.beginFill(color, 1);
  78. graphics.drawRect(0, 0, 100, 100);
  79. var tf = new TextField();
  80. tf.y = 110;
  81. tf.text = "click the box";
  82. addChild(tf);
  83. }
  84. }