Mouse Events and Overlapping Display Objects : MouseEvent « Development « Flash / Flex / ActionScript






Mouse Events and Overlapping Display Objects

 
package {
  import flash.display.*;
  import flash.events.*;
  import flash.text.*;

  public class Main extends Sprite {
    public function Main (  ) {
      var circle:Sprite = new Sprite(  );
      circle.graphics.beginFill(0x999999, 1);
      circle.graphics.lineStyle(1);
      circle.graphics.drawEllipse(0, 0, 100, 100);

      var textfield:TextField = new TextField(  );
      textfield.text = "Click here";
      textfield.autoSize = TextFieldAutoSize.LEFT;
      textfield.x = 30;
      textfield.y = 30;
      textfield.border = true;
      textfield.background = true;

      addChild(circle);
      addChild(textfield);

      circle.addEventListener(MouseEvent.CLICK, clickListener);
    }

    private function clickListener (e:MouseEvent):void {
      trace("User clicked: " + e.target);
      DisplayObject(e.target).x += 10;
    }
  }
}

        








Related examples in the same category

1.Responding to Mouse and Key Events
2.mouseEnabled = false
3.Finding the mouse pointer's position
4.A custom mouse pointer
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