Rollover Test : MouseEvent « Development « Flash / Flex / ActionScript






Rollover Test

 
package {
     
     import flash.display.Sprite;
     import flash.events.MouseEvent;
     
     [SWF(width=550, height=400)]

     public class Main extends Sprite {
     
          private static var UP_COLOR:uint = 0xFF0000;
          private static var ROLLOVER_COLOR:uint = 0x0000FF;
          
          private var _square:Sprite = new Sprite();
          
          public function Main() {
               drawSquare(UP_COLOR);
               addChild(_square);
               
               _square.doubleClickEnabled = true;
               
               _square.addEventListener(MouseEvent.CLICK, onSquareClick);
               _square.addEventListener(MouseEvent.DOUBLE_CLICK, onSquareDoubleClick);
               _square.addEventListener(MouseEvent.ROLL_OVER, onSquareRollOver);
               _square.addEventListener(MouseEvent.ROLL_OUT, onSquareRollOut); 
          }
          
          private function drawSquare(color:uint):void {
               _square.graphics.clear();
               _square.graphics.lineStyle(2, 0x000000);
               _square.graphics.beginFill(color);
               _square.graphics.drawRect(0, 0, 100, 100);
               _square.graphics.endFill();
          }
          
          private function onSquareClick(event:MouseEvent):void {
               trace("ouch!");
          }
          
          private function onSquareDoubleClick(event:MouseEvent):void {
               trace("double ouch!");
          }
          
          private function onSquareRollOver(event:MouseEvent):void {
               drawSquare(ROLLOVER_COLOR);
          }
          
          private function onSquareRollOut(event:MouseEvent):void {
               drawSquare(UP_COLOR);
          }
     }
}

        








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.Add mouse listener to state
13.Creating Mouse Interactions
14.Add mouse move listener
15.Add mouse up and down listener
16.Click Test
17.Post-Event Screen Updates