This is the result of a little experiment I was trying. Calling this one a “reclaimer” effect. One object pulling another object, one particle at a time.
Sorry but the code is uncommented.
View Code ACTIONSCRIPT
/** * VERSION: 1.0 * DATE: 3/12/2010 * AS3 * UPDATES AND DOCUMENTATION AT: http://www.FreeActionScript.com **/ package { import flash.display.BitmapData; import flash.display.Sprite; import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; public class Reclaimer extends Sprite { private var particlesCurrent:Number = 0; private var particlesTotal:Number = 50; private var particleSpeed:Number = 10; private var particleFadeoutSpeed:Number = .05; private var particlesArray:Array; private var radians:Number; public function Reclaimer():void { init(); } private function init():void { radians = 180 / Math.PI; particlesArray = []; addEventListener(Event.ENTER_FRAME, onEnterFrameLoop); thing1.addEventListener(MouseEvent.MOUSE_DOWN, onThingDown); thing2.addEventListener(MouseEvent.MOUSE_DOWN, onThingDown); thing1.addEventListener(MouseEvent.MOUSE_UP, onThingUp); thing2.addEventListener(MouseEvent.MOUSE_UP, onThingUp); } private function onThingDown(event:MouseEvent):void { event.currentTarget.startDrag(); } private function onThingUp(event:MouseEvent):void { event.currentTarget.stopDrag(); } private function createThing(target1:MovieClip, target2:MovieClip):void { if(particlesTotal <= particlesCurrent) { return; } particlesCurrent++; var tempParticle:Particle = new Particle(); tempParticle.x = target1.x + Math.random() * target1.width; tempParticle.y = target1.y + Math.random() * target1.height; tempParticle.rotation = Math.random()*360; tempParticle.rot = Math.atan2(target1.y - target2.y, target1.x - target2.x); tempParticle.xSpeed = Math.cos(tempParticle.rot) * radians / particleSpeed; tempParticle.ySpeed = Math.sin(tempParticle.rot) * radians / particleSpeed; particlesArray.push(tempParticle); addChild(tempParticle); } private function updateParticle():void { for (var i = 0; i < particlesArray.length; i++) { var tempParticle:MovieClip = particlesArray[i]; tempParticle.x -= tempParticle.xSpeed; tempParticle.y -= tempParticle.ySpeed; tempParticle.alpha -= particleFadeoutSpeed; if(tempParticle.hitTestObject(thing2)) { destroyParticle(tempParticle); } else if (tempParticle.alpha <= 0) { destroyParticle(tempParticle); } else if (tempParticle.x < 0) { destroyParticle(tempParticle); } else if (tempParticle.x > stage.stageWidth) { destroyParticle(tempParticle); } else if (tempParticle.y < 0) { destroyParticle(tempParticle); } else if (tempParticle.y > stage.stageHeight) { destroyParticle(tempParticle); } } } private function destroyParticle(particle:MovieClip):void { for (var i = 0; i < particlesArray.length; i++) { var tempParticle:MovieClip = particlesArray[i]; if (tempParticle == particle) { particlesCurrent--; particlesArray.splice(i,1); removeChild(tempParticle); } } } private function onEnterFrameLoop(event:Event):void { createThing(thing1, thing2); updateParticle(); } } } |

No Comments »