package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
import flash.text.TextField;
public class test002 extends Sprite
{
public function test002()
{
super();
init();
}
private const INIT_SEGMENTS:uint=10;
private const THICKNESS:uint=2;
private const COLOR:uint=0xFF0000;
private const ROTATION_RATE:uint=1;
private var shapeHolder:Sprite;
private var shapes:Vector.<Shape>;
private var myFilters:Array;
private function init():void
{
shapeHolder = new Sprite;
shapeHolder.x = stage.stageWidth>>1;
shapeHolder.y = stage.stageHeight >>1;
addChild(shapeHolder);
var bu:Sprite = new Sprite();
bu.graphics.beginFill(0x66CC);
bu.graphics.drawRect(0,0,100,30);
bu.graphics.endFill();
var t:TextField = new TextField;
t.text = "清理";
bu.addChild(t);
addChild(bu);
bu.mouseChildren = false;
bu.addEventListener(MouseEvent.CLICK,clickHandler);
shapes = new Vector.<Shape>();
for(var i:uint=0;i<INIT_SEGMENTS;i++){
addSegments();
}
postionSement();
myFilters = [new GlowFilter()];
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
}
private function addSegments():void
{
var shape:Shape = new Shape;
if(shapes.length>0){
shape.graphics.copyFrom(shapes[0].graphics);
}else{
shape.graphics.lineStyle(THICKNESS,COLOR);
}
shapes.push(shape);
shapeHolder.addChild(shape);
}
private function postionSement():void
{
var segments:uint = shapes.length;
var angle:Number = 360/segments;
for(var i:uint=1;i<segments;i++){
shapes[i].rotation = i*angle;
}
}
private function mouseDown(e:MouseEvent):void
{
var shape:Shape = shapes[0];
shape.graphics.lineTo(shape.mouseX,shape.mouseY);
addEventListener(Event.ENTER_FRAME,enterframe);
}
private function mouseUp(e:MouseEvent):void
{
removeEventListener(Event.ENTER_FRAME,enterframe);
}
private function enterframe(e:Event):void
{
shapeHolder.rotation = ROTATION_RATE;
draw();
}
private function draw():void
{
var shape:Shape = shapes[0];
shape.graphics.lineTo(shape.mouseX,shape.mouseY);
var segments:uint = shapes.length;
for(var i:uint=1;i<segments;i++){
shapes[i].graphics.copyFrom(shape.graphics);
}
}
private function clickHandler(e:MouseEvent):void
{
e.stopImmediatePropagation();
while(shapeHolder.numChildren){
var s:Shape = shapeHolder.removeChildAt(0) as Shape;
s.graphics.clear();
s = null;
}
shapeHolder = null;
init();
}
}
}