Chapter 21 Example 4

by actionscriptbible forked from Chapter 21 Example 1 (diff: 23)
♥0 | Line 28 | Modified 2009-08-27 06:17:53 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bJMD
 */

package {
  import flash.display.Sprite;
  public class ch21ex4 extends Sprite {
    public function ch21ex4() {
      var circ:ClickableCircle = new ClickableCircle();
      circ.x = circ.y = 100;
      addChild(circ);
    }
  }
}
import flash.display.Sprite;
import flash.events.MouseEvent;
class ClickableCircle extends Sprite {
  public function ClickableCircle(color:uint = 0, size:Number = 50) {
    graphics.beginFill(color, 0.25);
    graphics.drawCircle(0, 0, size);
    graphics.endFill();
    addEventListener(MouseEvent.ROLL_OVER, onRollOver);
    addEventListener(MouseEvent.ROLL_OUT, onRollOut);
    onRollOut(null); //start in the "up"/not hovered state.
  }
  protected function onRollOver(event:MouseEvent):void {
    alpha = 1;
  }
  protected function onRollOut(event:MouseEvent):void {
    alpha = 0.5;
  }
}