Reclaimer Effect

Friday, March 12th, 2010 | AS3 Effects | No Comments

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();
		}
 
	}	
}
Download Fla Sample

Download Fla Sample

Tags: , , , , ,

Contact form

Thursday, March 4th, 2010 | Site Updates | No Comments

Last week I added a contact form to the site. Unfortunately it wasn’t working correctly due to wordpress (shame on me for not doing additional tests!). So, if you used the contact form in the last week, I did not get your request.  Please resend.

OOP: XML Loader & Display Manager

Monday, February 15th, 2010 | AS3 Gadgets | No Comments

Here is an OOP XML Loader & Display Manager class that can be used in your projects to load and display XML data.

The XML comes in the following form:

<?xml version="1.0" encoding="utf-8" ?>
<data>
	<person name="Bob"></person>
	<person name="Jack"></person>
	<person name="Jill"></person>
</data>

Here is the SWF that loads it:

Class structure:
XML Loader & Display Manager

Download Fla Sample

Download Fla Sample

Tags: , , , , , ,