flash on 2009-8-10
クリックで動作します。as2でよく使ってる大量MCの順再生を3.0で書き直し。
8.11.2009 背景をランダムカラーに
/**
* Copyright iong ( http://wonderfl.net/user/iong )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/x552
*/
package
{
// クリックで動作します。as2でよく使ってる大量MCの順再生を3.0で書き直し。
// 8.11.2009 背景をランダムカラーに
import flash.display.Sprite;
import flash.display.BlendMode;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.utils.setInterval;
import flash.events.Event;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
[swf(width="465", height="465", backgroundColor="#ffffff")]
public class As005 extends Sprite
{
private var cv:BitmapData;
private var cPMain:Sprite;
private var cPBg:Sprite;
// 背景設定
private var aryBg:Array = new Array();
private var iBgW:uint = 31;
private var iBgH:uint = 31;
private var SICl:uint = 0;
public function As005():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate = 30;
init();
act();
}
private function init():void
{
cPMain = new pMain();
cPMain.x = stage.stageWidth/2;
cPMain.y = stage.stageHeight/2;
cPMain.scaleX = 0;
cPMain.scaleY = 0;
cPBg = new Sprite();
initBg();
addChild(cPBg);
addChild(cPMain);
}
private function act():void
{
SICl= setInterval(changeBg, 100);
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:Event):void
{
cPMain.addEventListener(Event.ENTER_FRAME, actMain);
cPBg.addEventListener(Event.ENTER_FRAME, actBg);
}
// ==================================================
// メイン
private function actMain(e:Event):void
{
e.target.scaleX += (e.target.scaleX==0) ? (50+Math.round(Math.random()*200))/100: 1.5;
e.target.scaleY = e.target.scaleX;
e.target.removeEventListener(Event.ENTER_FRAME, actMain);
e.target.addEventListener(Event.ENTER_FRAME, actMainFO);
}
private function actMainFO(e:Event):void
{
e.target.scaleX += (0-e.target.scaleX)*.2;
e.target.scaleY += (0-e.target.scaleY)*.2;
if(Math.abs(0-e.target.scaleX)<=0.01){
e.target.removeEventListener(Event.ENTER_FRAME, actMainFO);
e.target.scaleX=0;
e.target.scaleY=0;
}
}
// ==================================================
// 背景配置
private function initBg():void
{
var tmpLI:uint = Math.ceil(stage.stageWidth/iBgW);
var tmpLC:uint = Math.ceil(stage.stageHeight/iBgH);
for(var i:uint=0; i<=tmpLI; i++){
aryBg[i]= new Array();
for(var cc:uint=0; cc<=tmpLC; cc++){
var tmc:Sprite = new pBg(iBgW, iBgH, retC());
tmc.name = "bg"+i+"_"+cc;
tmc.x = i*iBgW + 0.2;
tmc.y = cc*iBgH+ 0.2;
aryBg[i][cc] = new Object();
aryBg[i][cc] = {
mc:tmc
,cmax: Math.abs(tmpLI/2-i) + Math.abs(tmpLC/2-cc)
,cnt: 0
,flgfo: false
,cl: new Array(0,0,0)
};
cPBg.addChild(tmc);
}
}
}
// 背景動作
private function actBg(e:Event):void
{
for(var i:uint=0; i<aryBg.length; i++){
for(var cc:uint=0; cc<aryBg[i].length; cc++){
var tmc:Sprite = aryBg[i][cc].mc;
aryBg[i][cc].flgfo = false;
tmc.addEventListener(Event.ENTER_FRAME, actBgPiece);
}
}
cPBg.removeEventListener(Event.ENTER_FRAME, actBg);
}
private function actBgPiece(e:Event):void
{
var tp:Array = e.target.name.split("_");
var i:uint = uint(tp[0].substr(2));
var cc:uint = uint(tp[1]);
if(aryBg[i][cc].cnt<aryBg[i][cc].cmax){
aryBg[i][cc].cnt++;
}else{
e.target.alpha = (aryBg[i][cc].flgfo)
? Math.min(1, e.target.alpha+.2)
: Math.max(0, e.target.alpha-.2);
if(e.target.alpha==0) aryBg[i][cc].flgfo= true;
if(e.target.alpha==1){
aryBg[i][cc].cnt = 0;
e.target.removeEventListener(Event.ENTER_FRAME, actBgPiece);
}
}
}
// 色変更
private function changeBg():void
{
for(var i:uint=0; i<=5; i++){
var tmpI:uint = Math.round(Math.random()*(aryBg.length-1));
var tmpC:uint = Math.round(Math.random()*(aryBg[0].length-1));
var target:Sprite = aryBg[tmpI][tmpC].mc;
aryBg[tmpI][tmpC].cl= retCOffset();
var seekerBg:Sprite = new Sprite();
seekerBg.name = "sk"+tmpI+"_"+tmpC;
seekerBg.addEventListener(Event.ENTER_FRAME, changeBgColor);
}
}
private function changeBgColor(e:Event):void
{
var tmpName:Array = e.target.name.substr(2).split("_");
var tmpI:uint = int(tmpName[0]);
var tmpC:uint = int(tmpName[1]);
var tmc:Sprite = aryBg[tmpI][tmpC].mc;
var rOffset:Number = Math.round((tmc.transform.colorTransform.redOffset +aryBg[tmpI][tmpC].cl[0])/2);
var gOffset:Number = Math.round((tmc.transform.colorTransform.greenOffset+aryBg[tmpI][tmpC].cl[1])/2);
var bOffset:Number = Math.round((tmc.transform.colorTransform.blueOffset +aryBg[tmpI][tmpC].cl[2])/2);
tmc.transform.colorTransform = new ColorTransform(1, 1, 1, 1, rOffset, gOffset, bOffset, 0);
if(Math.abs(rOffset-aryBg[tmpI][tmpC].cl[0])<=1 && Math.abs(gOffset-aryBg[tmpI][tmpC].cl[1])<=1 && Math.abs(bOffset-aryBg[tmpI][tmpC].cl[2])<=1){
e.target.removeEventListener(Event.ENTER_FRAME, changeBgColor);
}
}
// ==================================================
private function retC():Number
{
var coR:String= (100+Math.round(Math.random()*155)).toString(16);
var coG:String= (100+Math.round(Math.random()*155)).toString(16);
var coB:String= (100+Math.round(Math.random()*155)).toString(16);
return parseInt("0x"+coR+coG+coB, 16)
}
private function retCOffset():Array
{
var ofR:int = -50+Math.round(Math.random()*100);
var ofG:int = -50+Math.round(Math.random()*100);
var ofB:int = -50+Math.round(Math.random()*100);
var retVal:Array = new Array(ofR, ofG, ofB);
return retVal;
}
}
}
import flash.display.Sprite;
// メイン
class pMain extends Sprite
{
public function pMain():void
{
graphics.beginFill(0xff0000, 1);
graphics.moveTo(0, -26);
graphics.curveTo(0,-50, -25,-50);
graphics.curveTo(-60,-50, -60,-12);
graphics.curveTo(-60,22, 0,50);
graphics.lineTo(0,50);
graphics.curveTo(60,22, 60,-12);
graphics.curveTo(60,-50, 25,-50);
graphics.curveTo(0,-50, 0,-26);
graphics.endFill();
}
}
// 背景
class pBg extends Sprite
{
public function pBg(iBgW:uint, iBgH:uint, iC:Number):void
{
graphics.beginFill(iC, 1);
graphics.moveTo(-(iBgW/2-0.5), -(iBgH/2-0.5));
graphics.lineTo(-(iBgW/2-0.5), iBgH/2-0.5);
graphics.lineTo(iBgW/2-0.5, iBgH/2-0.5);
graphics.lineTo(iBgW/2-0.5, -(iBgH/2-0.5));
graphics.endFill();
}
}