RandomNumber on 2010-01-26
/**
* Copyright komatsu ( http://wonderfl.net/user/komatsu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/p0R0
*/
package {
import flash.text.TextField;
import flash.display.Sprite;
import caurina.transitions.Tweener;
[SWF(backgroundColor="#000000", frameRate=30)]
public class RamdomRectangle extends Sprite {
public function RamdomRectangle() {
var rndAry:Array = new Array();
const MAX_CNT:uint = 75;
var i:uint;
for(i=1;i<=MAX_CNT;i++){
rndAry.push(i);
}
rndAry = Shuffle.setRandom(rndAry);
for(i=0;i<MAX_CNT;i++){
var sp:Sprite = new Sprite();
sp.graphics.beginFill(Math.random()*0xFFFFFF);
sp.graphics.drawRect(0,0,50,50);
sp.x = sp.width*(i%10);
sp.y = sp.height*(Math.floor(i/10));
var tf:TextField = new TextField();
tf.text = String(rndAry[i]);
sp.addChild(tf);
sp.alpha = 0;
Tweener.addTween(sp , {alpha:1 , delay:(i+1)/5,time:5});
addChild(sp);
}
}
}
}
class Shuffle{
/*配列のシャッフルをする関数*/
static public function setRandom(ary:Array):Array{
var baseAry:Array = ary;
var returnAry:Array = new Array();
var rndCnt:uint = ary.length;
for(var i:uint=0;i<rndCnt;i++){
var rnd:uint = Math.floor(Math.random()*baseAry.length);
returnAry.push(baseAry[rnd]);
baseAry.splice(rnd,1);
}
return returnAry;
}
}