squares
package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
import flash.geom.Point;
[SWF(backgroundColor=0x000000, frameRate=24)]
public class Squares extends Sprite
{
private var current:Shape;
private var currentColor:uint;
private var mouseDown:Point;
public function Squares():void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
}
private function startDrawing(e:MouseEvent):void {
addChild(current = new Shape()).filters = [new GlowFilter(0, 0.7, 20, 20, 1)];
currentColor = Math.random() * 0xFFFFFF;
mouseDown = new Point(stage.mouseX, stage.mouseY);
stage.addEventListener(MouseEvent.MOUSE_MOVE, drawing);
}
private function stopDrawing(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawing);
}
private function drawing(e:Event):void {
current.graphics.clear();
current.graphics.lineStyle(1, currentColor);
current.graphics.beginFill(currentColor, 0.3);
current.graphics.drawRect(mouseDown.x, mouseDown.y, stage.mouseX - mouseDown.x, stage.mouseY - mouseDown.y);
current.graphics.endFill();
}
}
}