Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. private function added():void
  2. {
  3. removeEventListener(Event.ADDED, added);
  4. this.addEventListener(TouchEvent.TOUCH, onTouch);
  5. }
  6.  
  7. protected function onTouch(e:TouchEvent):void
  8. {
  9. var touchHover:Touch = e.getTouch(this, TouchPhase.HOVER);
  10.  
  11. if (touchHover)
  12. {
  13. trace("show");
  14. //mouse is hovered over this object. Therefore call Hovertext:
  15. if (Game.hoverText.message != name_)
  16. Game.hoverText.message = name_
  17. }
  18. else
  19. {
  20. //mouse leaves the object
  21. trace("hide");
  22. Game.hoverText.hideMessage(name_);
  23. }
  24.  
  25. }
  26.  
  27. var touch:Touch = event.getTouch(this);
  28.  
  29. if (touch == null) {
  30. // Set Object alpha to 0;
  31. //trace("pois");
  32. Game.hoverText.hideMessage(name_);
  33. }
  34. else if (touch.phase == TouchPhase.HOVER) {
  35. // Set Object alpha to 1;
  36. //trace("paalla");
  37. if (Game.hoverText.message != name_)
  38. Game.hoverText.message = name_;
  39. }
  40. else {
  41. // for a phase BEGIN/MOVE/STATIONARY case
  42. // see if the touch is over the bounds of the tile (assuming 'this' is the tile)
  43. HELPER_POINT.x = touch.globalX;
  44. HELPER_POINT.y = touch.globalY;
  45. this.globalToLocal(HELPER_POINT, HELPER_POINT);
  46. if(this.hitTest(HELPER_POINT, true) != null)
  47. {
  48. // Set Object alpha to 1; over tile
  49. trace("paalla");
  50. }
  51. else
  52. {
  53. // Set Object alpha to 0; not over tile
  54. trace("pois");
  55. }
  56.  
  57. var touchHover:Touch = e.getTouch(this);
  58.  
  59. if (touchHover && touchHover.phase == TouchPhase.HOVER)
  60. {
  61. trace("show");
  62. //mouse is hovered over this object. Therefore call Hovertext:
  63. if (Game.hoverText.message != name_)
  64. Game.hoverText.message = name_
  65. }
  66.  
  67. if (touchHover == null)
  68. {
  69. //mouse leaves the object
  70. trace("hide");
  71. Game.hoverText.hideMessage(name_);
  72. }
  73.  
  74. private function isPressed(event:TouchEvent):void
  75. {
  76. var touch:touch = event.getTouch(this);
  77.  
  78. if(touch.phase == TouchPhase.BEGAN){
  79. trace("show");
  80. //mouse is hovered over this object. Therefore call Hovertext:
  81. if (Game.hoverText.message != name_)
  82. Game.hoverText.message = name_
  83. } else if(touch.phase == TouchPhase.ENDED){
  84. trace("release");
  85.  
  86. //stop doing stuff
  87. removeEventListener(Event.ENTER_FRAME, onButtonHold);
  88. }
  89. }
  90.  
  91. import starling.events.Touch;
  92. import starling.events.TouchEvent;
  93. import starling.events.TouchPhase;
  94.  
  95. private var touches:Vector.<Touch>;
  96. private var touch:Touch;
  97. private var touchStage:Touch;
  98.  
  99. private function onTouch(e:TouchEvent=null):void {
  100.  
  101. touches= e.getTouches(DisplayObject(e.target));
  102. if (touches.length == 1)
  103. {
  104. touch = touches[0];
  105.  
  106. if (touch.phase == TouchPhase.BEGAN){
  107. m_TouchTarget = touch.target;
  108. //HERE IS A MOUSE DOWN
  109. }
  110.  
  111. if (touch.phase == TouchPhase.ENDED){
  112. m_TouchEndedPoint = new Point(touch.globalX, touch.globalY);
  113.  
  114. if (stage.hitTest(m_TouchEndedPoint, true) == m_TouchTarget)
  115. {
  116. //HERE IS A MOUSE UP
  117. }
  118. }
  119. if (touch.phase == TouchPhase.MOVED){
  120. m_TouchEndedPoint = new Point(touch.globalX, touch.globalY);
  121. //HERE IS A MOUSE OUT
  122.  
  123. if (stage.hitTest(m_TouchEndedPoint, true) != m_TouchTarget)
  124. {
  125. //HERE IS A MOUSE OVER
  126. }
  127. }
  128.  
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement