[1日1Wonderfl] 8日目:a practice of BetweenAS3
package {
import flash.display.Sprite;
import flash.events.*;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.easing.*;
public class FlashTest extends Sprite {
public function FlashTest() {
createParticle();
stage.addEventListener( MouseEvent.CLICK, onclick );
}
private function onclick(e:Event) :void {
while( numChildren > 0) removeChildAt(0);
createParticle( Math.random() * 1000+300 );
}
public function createParticle( cnt:uint = 400 ):void {
var tList:Array = [];
for( var i:int=0; i<cnt; ++i ) {
var ball:Sprite = new Ball( Math.random()*6, 0xFF*(i/cnt)<<16 | 0x6666 );
addChild( ball );
ball.x = ball.y = 230;
ball.alpha = 0;
var a:Number=Math.random()*2*Math.PI;
var radius:Number = 300* Math.random() + 100;
var delay:Number = Math.random()+0.3;
var tx:Number=Math.cos( a )* radius;
var ty:Number=Math.sin( a )* radius;
var t1:ITween = BetweenAS3.tween( ball, { x:tx+230, y:ty+230 }, null, 3, Circ.easeOut, delay );
var t2:ITween = BetweenAS3.tween( ball, { alpha:1 }, null, 0.3, null, delay );
tList.push( t1, t2 );
}
var t:ITween = BetweenAS3.parallel.apply( null, tList );
t.play();
}
}
}
import flash.display.*;
internal class Ball extends Sprite{
public function Ball( r:Number=4, c:uint =0x003366 ) {
graphics.beginFill( c);
graphics.drawCircle( 0, 0, r );
graphics.endFill();
}
}