Add mouse listener to state : MouseEvent « Development « Flash / Flex / ActionScript






Add mouse listener to state

 

package {
  import flash.display.*;
  import flash.events.*;
  public class GetChildAtExample extends Sprite {
    public function GetChildAtExample(  ) {
   
      var color:Array = [ 0xFF0000, 0x990000, 0x660000, 0x00FF00,
                          0x009900, 0x006600, 0x0000FF, 0x000099,
                          0x000066, 0xCCCCCC ];
   
      for ( var i:int = 0; i < 10; i++ ) {
        var circle:Shape = createCircle( color[i], 10 );
        circle.x = i;
        circle.y = i + 10; // the + 10 adds padding from the top
        
        addChild( circle );
      }      
      
      stage.addEventListener( MouseEvent.CLICK, updateDisplay );
    }
   
    public function updateDisplay( event:MouseEvent ):void {
      setChildIndex( getChildAt(0), numChildren - 1 );
    }
    
    public function createCircle( color:uint, radius:Number ):Shape {
      var shape:Shape = new Shape(  );
      shape.graphics.beginFill( color );
      shape.graphics.drawCircle( 0, 0, radius );
      shape.graphics.endFill(  );
      return shape;
    }
  }
}
                          

        








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.A custom mouse pointer
6.Handling Mouse Events "Globally"
7.Global Mouse Down Sensor
8.Mouse Events and Modifier Keys
9.Mouse Event Hierarchy
10.All types of mouse event
11.Using MouseEvent in Conjunction with the Mouse
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