package { import com.flashdynamix.motion.TweensyGroup; import flash.display.Shape; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.ColorTransform; /** * A very simple ui-test for Tweensy to see how the TweensyGroup API works * * (c) 2009 alecmce.com * * @author Alec McEachran */ public class TweensyGroupTest extends Sprite { private const COLORS:Array = [0xFF0000, 0xFF8800, 0xFFEE00, 0x00FF00, 0x1E90FF, 0x0000CD, 0x9900FF]; private const SIZE:int = 50; private var tweens:TweensyGroup; private var tweening:Boolean; public function TweensyGroupTest() { tweening = false; var nx:int = stage.stageWidth / SIZE; var ny:int = stage.stageHeight / SIZE; for (var x:int = 0; x < nx; x++) { for (var y:int = 0; y < ny; y++) createTile(x, y); } stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); } private function onMouseMove(event:MouseEvent):void { if (!tweening) checkMouseAndTween(); } private function checkMouseAndTween():void { if (stage.mouseX < 0 || stage.mouseX > stage.stageWidth) return; if (stage.mouseY < 0 || stage.mouseY > stage.stageHeight) return; createTweens(); tweening = true; } private function restartTweening():void { tweening = false; checkMouseAndTween(); } private function createTweens():void { tweens = new TweensyGroup(); tweens.onComplete = restartTweening; var len:int = numChildren; for (var i:int = 0; i < len; i++) { var shape:Shape = Shape(getChildAt(i)); var transform:ColorTransform = new ColorTransform(); transform.color = getRandomColor(); tweens.colorTransformTo(shape, transform); } } private function createTile(x:int, y:int):Shape { var shape:Shape = new Shape(); shape.x = x * SIZE; shape.y = y * SIZE; shape.graphics.beginFill(getRandomColor()); shape.graphics.drawRect(0, 0, SIZE, SIZE); shape.graphics.endFill(); addChild(shape); return shape; } private function getRandomColor():int { return COLORS[int(Math.random() * COLORS.length)]; } } }