머리가 나뻐서 삽질 SAP(Study And Programming)
particle
그냥 만든거... 마우스 왼쪽버튼 누른 후 이동하거나 떼었을 때 반응이 있다.
code
fla에는 BG_mc, Star_mc 이렇게 두개의 인스턴스가 라이브러리에 있어야 한다.
Main.as
package { import Star_mc; import StarMoving; import TimerClass; import caurina.transitions.Tweener; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.display.Stage; import flash.geom.ColorTransform; import flash.utils.setTimeout; import flash.display.DisplayObject; import flash.events.MouseEvent; [SWF(frameRate="30", backgroundColor='#FFFFFF', width="800", height="600")] public class Main extends Sprite{ private const TOTAL:uint = 70; private var displayObject:DisplayObject; private var _starArr:Array = []; private var _starMovingArr:Array = []; private var _bg_mc:MovieClip; public function Main() { if(stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void{ displayObject = this; _bg_mc = new BG_mc(); addChild(_bg_mc); _bg_mc.alpha = 0; for(var i:uint=0; i<TOTAL; ++i) { var star_mc:Star_mc = new Star_mc(); var starMoving:StarMoving = new StarMoving(star_mc, stage); _starArr.push(star_mc); _starMovingArr.push(starMoving); this.addChild(star_mc); star_mc.x = (stage.stageWidth - star_mc.width)/2; star_mc.y = (stage.stageHeight - star_mc.height)/2; } stage.addEventListener(MouseEvent.MOUSE_DOWN, inTogether); stage.addEventListener(MouseEvent.MOUSE_UP, outTogether); //var timerClass:TimerClass = new TimerClass(starMoving, stage); } private function inTogether(e:MouseEvent):void { for(var i:uint=0; i<TOTAL; ++i) { _starMovingArr[i].removeEventLoop(); //Tweener.addTween(_starArr[i], {x:stage.mouseX, y:stage.mouseY, delay:i*0.005, time:1, transition:"easeOutExpo"}); Tweener.addTween(_starArr[i], {x:stage.mouseX, y:stage.mouseY, time:(i*0.03)+0.3, transition:"easeOutExpo"}); } _bg_mc.alpha = 0; Tweener.addTween(_bg_mc, {alpha:1, time:5, transition:"easeOutExpo"}); if(!stage.hasEventListener(MouseEvent.MOUSE_MOVE))stage.addEventListener(MouseEvent.MOUSE_MOVE, moveTogether); } private function outTogether(e:MouseEvent):void { for(var i:uint=0; i<TOTAL; ++i) { _starMovingArr[i].addEventLoop(); } Tweener.addTween(_bg_mc, {alpha:0, time:1, transition:"easeOutExpo"}); stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveTogether); } private function moveTogether(e:MouseEvent):void { for(var i:uint=0; i<TOTAL; ++i){ //Tweener.addTween(_starArr[i], {x:stage.mouseX, y:stage.mouseY, delay:i*0.005, time:.1, transition:"easeOutExpo"}); Tweener.addTween(_starArr[i], {x:stage.mouseX, y:stage.mouseY, time:(i*0.03)+0.3, transition:"easeOutExpo"}); } } } }
StarMoving.as
package { import Star_mc; import flash.display.Stage; import flash.events.Event; import flash.filters.GlowFilter; import flash.geom.ColorTransform; public class StarMoving { private var _stage:Stage; private var _star_mc:Star_mc; private var _vx:Number; private var _vy:Number; private var _rot:int = 5; public function StarMoving($star_mc:Star_mc, $stage:Stage) { // constructor code _star_mc = $star_mc; _stage = $stage; init(); } private function init():void { _vx = randomize(-5, 5); _vy = randomize(-5, 5); _star_mc.scaleX = _star_mc.scaleY = randomize(0.7, 1.5); var glow:GlowFilter = new GlowFilter(); glow.color = 0xFFFFFF * Math.random(); _star_mc.filters = [glow]; var ct:ColorTransform = new ColorTransform(); ct.color = Math.random()* 0xFFFFFF; _star_mc.transform.colorTransform = ct; _star_mc.alpha = Math.random(); addEventLoop(); } public function addEventLoop():void { if( !_star_mc.hasEventListener(Event.ENTER_FRAME) ){ _star_mc.addEventListener(Event.ENTER_FRAME,loop); } } public function removeEventLoop():void { _star_mc.removeEventListener(Event.ENTER_FRAME,loop); } private function randomize($min:int, $max:int):Number { return Math.random() * ($max - $min) + $min; } private function loop(e:Event):void { if ( _star_mc.x < Math.ceil(_star_mc.width/2) ) { _star_mc.x = Math.ceil(_star_mc.width/2); _vx = - _vx; _rot = - _rot; } if( _star_mc.x > Math.ceil(_stage.stageWidth- _star_mc.width/2) ) { _star_mc.x = Math.ceil(_stage.stageWidth- _star_mc.width/2); _vx = - _vx; _rot = - _rot; } if ( _star_mc.y < Math.ceil(_star_mc.height/2) ) { _star_mc.y = Math.ceil(_star_mc.height/2); _vy = - _vy; _rot = - _rot; } if( _star_mc.y > Math.ceil(_stage.stageHeight- _star_mc.height/2) ) { _star_mc.y = Math.ceil(_stage.stageHeight- _star_mc.height/2); _vy = - _vy; _rot = - _rot; } _star_mc.x += _vx; _star_mc.y +=_vy; _star_mc.rotation +=_rot; } } }