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

Home
Flash / Flex / ActionScript
1.Animation
2.Array
3.Class
4.Data Type
5.Development
6.Function
7.Graphics
8.Language
9.Network
10.Regular Expressions
11.Statement
12.String
13.TextField
14.XML
Flash / Flex / ActionScript » 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;
      }
    }
  }
}

        














Related examples in the same category
1.Responding to Mouse and Key Events
2.Mouse Events and Overlapping Display Objects
3.mouseEnabled = false
4.Finding the mouse pointer's position
5.Handling Mouse Events "Globally"
6.Global Mouse Down Sensor
7.Mouse Events and Modifier Keys
8.Mouse Event Hierarchy
9.All types of mouse event
10.Using MouseEvent in Conjunction with the Mouse
11.Add mouse listener to state
12.Creating Mouse Interactions
13.Add mouse move listener
14.Add mouse up and down listener
15.Rollover Test
16.Click Test
17.Post-Event Screen Updates
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.