flash on 2011-5-12
...
@author gaina
/**
* Copyright gaina ( http://wonderfl.net/user/gaina )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/sHql
*/
package
{
import caurina.transitions.Tweener;
import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author gaina
*/
public class Main extends Sprite
{
private var _width:Number;
private var _height:Number;
private var _container:Sprite;
private var _grids:Array = [];
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
_width = stage.stageWidth;
_height = stage.stageHeight;
_container = new Sprite();
addChild(_container);
grid();
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void
{
grid();
}
private function grid():void
{
var gx:int = Math.ceil(_width / 50);
var gy:int = Math.ceil(_height / 50);
if (_grids.length > 0) {
for (var g:int = 0; g < _grids.length; g++) {
_container.removeChild(_grids[g] as DisplayObject);
_grids[g] = null;
}
}
_grids = [];
for (var i:int = 0; i < gx; i++) {
for (var j:int = 0; j < gy; j++) {
var p:Shape = new Shape();
p.graphics.beginFill(0);
p.graphics.drawRect(0, 0, 50, 50);
p.x = i * 50;
p.y = j * 50;
_grids.push(p);
_container.addChild(p);
}
}
animateGrid(shuffle(_grids));
}
private function animateGrid(arr:Array):void
{
Tweener.removeAllTweens();
var _len:int = arr.length;
for (var i:int = 0; i < _len; i++) {
var p:Shape = arr[i] as Shape;
if (i != _len -1) {
var XY:int = i % 2;
if (XY == 1) {
Tweener.addTween(p, { time:0.5, delay:1 + i / 200, scaleY:0, transition:"easeInOutBack" } );
}else {
Tweener.addTween(p, { time:0.5, delay:1 + i / 200, scaleX:0, transition:"easeInOutBack" } );
}
}else {
Tweener.addTween(p, { x:_width / 2, y:_height / 2, scaleX:0, scaleY:0, rotation:720, time:0.5, delay:3 + i / 200, transition:"easeInOutBack" });
}
}
}
/***********
* 配列のシャッフル
*************/
private function shuffle(array:Array):Array
{
var _arr:Array = array;
var _len:int = array.length;
while (_len) {
var n:int = Math.floor(Math.random() * _len);
var data:Shape = _arr[--_len];
_arr[_len] = _arr[n];
_arr[n] = data;
}
return _arr;
}
}
}