A custom mouse pointer : MouseEvent : Development Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Development » MouseEvent »

 

A custom mouse pointer


 
package {
  import flash.display.*;
  import flash.ui.*;
  import flash.events.*;
  import flash.geom.*;

  public class CustomMousePointer extends Sprite {
    public function CustomMousePointer (  ) {
      graphics.lineStyle(1);
      graphics.beginFill(0x0000FF1);
      graphics.lineTo(155);
      graphics.lineTo(515);
      graphics.lineTo(00);
      graphics.endFill(  );

      var stageDetector:StageDetector = new StageDetector(this);
      stageDetector.addEventListener(StageDetector.ADDED_TO_STAGE,
                                     addedToStageListener);
      stageDetector.addEventListener(StageDetector.REMOVED_FROM_STAGE,
                                     removedFromStageListener);
    }

    private function addedToStageListener (e:Event):void {
      Mouse.hide(  );

      stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
      stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveListener);
    }

    private function removedFromStageListener (e:Event):void {
      Mouse.show(  );
      stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
      stage.removeEventListener(Event.MOUSE_LEAVE, mouseLeaveListener);
    }

    private function mouseLeaveListener (e:Event):void {
      visible = false;
    }

    private function mouseMoveListener (e:MouseEvent):void {
      var pointInParent:Point = parent.globalToLocal(new Point(e.stageX,
                                                               e.stageY));
      x = pointInParent.x;
      y = pointInParent.y;

      e.updateAfterEvent(  );

      if (!visible) {
        visible = true;
      }
    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Development
» MouseEvent