PageRenderTime 25ms CodeModel.GetById 39ms RepoModel.GetById 3ms app.codeStats 0ms

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

http://touchmypixel.googlecode.com/
Haxe | 131 lines | 79 code | 31 blank | 21 comment | 0 complexity | cf62a63df3b6252d8bada14f4116a765 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 var onClick:Signal1<Int>;
  26. public function new()
  27. {
  28. super();
  29. Lib.current.addChild(this);
  30. //testAS3();
  31. testAS3Shortcuts();
  32. onClick = new Signal1();
  33. onClick.add(clicker);
  34. onClick.dispatch(
  35. }
  36. function clicker(i)
  37. {
  38. trace("X");
  39. }
  40. /*
  41. 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.
  42. */
  43. public function testAS3()
  44. {
  45. var box = new Box(0xffff00);
  46. addChild(box);
  47. var onClick = new AS3Signal(box, MouseEvent.CLICK);
  48. onClick.add(function(e){
  49. trace("clicked");
  50. });
  51. }
  52. /*
  53. Signals can be injected to InteractiveObjects via the 'using' feature. This makes for very concise code.
  54. */
  55. public function testAS3Shortcuts()
  56. {
  57. var box = new Box(0xff0000);
  58. box.x = 200;
  59. addChild(box);
  60. box.onClick().add(function(e) {
  61. trace("onClick");
  62. });
  63. box.onRollOver().add(function(e) {
  64. trace("onRollOver");
  65. });
  66. box.onRollOut().add(function(e) {
  67. trace("onRollOut");
  68. });
  69. box.onMouseDown().add(function(e) {
  70. trace("onMouseDown");
  71. });
  72. box.onMouseUp().add(function(e) {
  73. trace("onMouseUp");
  74. });
  75. box.onReleaseOutside().add(function(e) {
  76. trace("** onReleaseOutside ** (HELL YEAH!)");
  77. });
  78. box.onReleaseOutside(
  79. }
  80. }
  81. class Box extends flash.display.Sprite
  82. {
  83. public function new(color:Int)
  84. {
  85. super();
  86. graphics.beginFill(color, 1);
  87. graphics.drawRect(0, 0, 100, 100);
  88. var tf = new TextField();
  89. tf.y = 110;
  90. tf.text = "click the box";
  91. addChild(tf);
  92. }
  93. }