setterについて
/**
* Copyright atsumo ( http://wonderfl.net/user/atsumo )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4h6P
*/
/**
*
*/
package {
import flash.events.MouseEvent;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
initialize();
}
private function initialize():void
{
var ball = new Ball();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
ball.addEventListener(MouseEvent.ROLL_OVER, handleRollOver);
ball.addEventListener(MouseEvent.ROLL_OUT, handleRollOut);
ball.addEventListener(MouseEvent.CLICK, handleClick);
ball.buttonMode = true;
addChild(ball);
}
private function handleRollOver(e:MouseEvent):void
{
var ball:Ball = e.target as Ball;
ball.radius = 150;
}
private function handleRollOut(e:MouseEvent):void
{
var ball:Ball = e.target as Ball;
ball.radius = 50;
}
private function handleClick(e:MouseEvent):void
{
var ball:Ball = e.target as Ball;
//ball
ball.color = Math.random()*0xFFFFFF;
}
}
}
import flash.display.Graphics;
import flash.display.Sprite;
class Ball extends Sprite
{
private var _color:uint;
private var _radius:int;
public function Ball(color:uint = 0x0, radius:int = 50)
{
_color = color;
_radius = radius;
draw();
}
private function draw():void
{
var g:Graphics = this.graphics;
g.clear();
g.beginFill(_color);
g.drawCircle(0,0, _radius);
g.endFill();
}
public function set color(value:uint):void
{
_color = value;
draw();
}
public function set radius(value:int):void
{
_radius = value;
draw();
}
}