forked from: 原形視覚化
// forked from Jjoriping's 原形視覚化
package {
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.events.Event;
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.quality = "low";
graphics.beginFill(0);
graphics.drawRect(-1024,-1024,2048,2048);
var changeTimer:uint;
var traceText:TextField = new TextField();
var traceTextFormat:TextFormat = new TextFormat("Malgun Gothic",12,0xFFFFFF);
traceText.autoSize = "left";
traceText.selectable = false;
traceText.defaultTextFormat = traceTextFormat;
function trace(arg:*):void{
traceText.text = arg;
}
var VS:Sprite = new Sprite();
addChild(VS);
addChild(traceText);
var whiteSprite:Sprite = new Sprite();
whiteSprite.visible = false;
addChild(whiteSprite);
var colorArray:Array = [[0x5555FF,0xFFFF00,0x00FFFF],[0xFF5555,0x7777FF,0xFF7777],[0x55FF55,0xDD77DD,0x77FF77]];
var colorIndex:uint = 0;
var chosenColor:Array = colorArray[colorIndex];
var BGM:Sound = new Sound(new URLRequest("http://Jjoriping.ufree.kr/download/example3.mp3"));
var BGC:SoundChannel = new SoundChannel();
BGM.addEventListener(ProgressEvent.PROGRESS,bgmLoadingHandler);
BGM.addEventListener(Event.COMPLETE,bgmCompleteHandler);
function bgmLoadingHandler(e:ProgressEvent):void{
trace("Loading... "+int(e.bytesLoaded/e.bytesTotal*100)+"%");
}
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
function mouseDownHandler(e:MouseEvent):void{
changeColor();
changeForm();
}
function changeColor():void{
colorIndex++;
if(colorIndex >= colorArray.length){
colorIndex = 0;
}
chosenColor = colorArray[colorIndex];
updateWhiteSprite();
}
function updateWhiteSprite():void{
whiteSprite.graphics.clear();
whiteSprite.graphics.beginFill(chosenColor[0],0.5);
whiteSprite.graphics.drawRect(-2048,-2048,4096,4096);
}
function bgmCompleteHandler(e:Event):void{
trace("");
BGC = BGM.play();
changeTimer = 250;
whiteSprite.visible = true;
updateWhiteSprite();
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
var nowPeak:Number;
var targetZ:Number = 0;
function enterFrameHandler(e:Event):void{
nowPeak = (BGC.leftPeak+BGC.rightPeak)/2;
newCircle(int(nowPeak*3.2));
changeTimer--;
if(changeTimer == 0){
changeForm();
}
whiteSprite.alpha = nowPeak/2;
targetZ = nowPeak*1500;
VS.z += (targetZ-VS.z)/3;
}
var moveDir:Array = [0,1];
function changeForm():void{
changeTimer = 250;
moveDir = [Math.random()*6-3,Math.random()*6-3];
}
function newCircle(num:uint):void{
for(var i:uint=0;i<num;i++){
var nC:MovieClip = new MovieClip();
nC.graphics.beginFill(chosenColor[1],0.4);
nC.graphics.drawCircle(Math.random()*2000-1000,Math.random()*2000-1000,nowPeak*170);
VS.addChild(nC);
nC.addEventListener(Event.ENTER_FRAME,sEFHandler);
var nCi:Sprite = new Sprite();
nC.nCi = nCi;
nC.addChild(nCi);
}
}
function sEFHandler(e:Event):void{
e.target.x += nowPeak*20*moveDir[0];
e.target.y += nowPeak*20*moveDir[1];
e.target.alpha -= nowPeak/10;
e.target.nCi.graphics.beginFill(chosenColor[2],0.3);
e.target.nCi.graphics.drawCircle(Math.random()*2000-1000,Math.random()*2000-1000,nowPeak*30);
if(e.target.alpha <= 0){
e.target.removeEventListener(Event.ENTER_FRAME,sEFHandler);
VS.removeChild(VS.getChildByName(e.target.name));
}
}
}
}
}