A new trails animation with a blur effect and a motion of the objects animated towards you. Please note: This is a work in progress and the Main.as file needs to be cleaned up so there aren’t 2 entries for the image load when the movie clip is duplicated.
package
{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Main extends MovieClip
{
private var clip_arr:Array; // an array of clips
private var clip_ct:Number = 0;
private const RADIUS:int=30;
private const FRICTION:Number=.95;
public function Main()
{
init();
}
private function init():void
{
stage.frameRate=31;
clip_arr = new Array();
var myTimer:Timer = new Timer(5000, 10);
myTimer.addEventListener("timer", createClip);
myTimer.start();
}
private function createClip(e:TimerEvent):void
{
var randXOffset = Math.random() * stage.stageWidth;
var randYOffset = Math.random() * stage.stageHeight;
clip_arr.push ( new Image("smiley.png") );
clip_arr[clip_ct].scaleX = clip_arr[clip_ct].scaleY = 0;
clip_arr[clip_ct].x=Math.cos(clip_arr[clip_ct].angle*1)*RADIUS + randXOffset;
clip_arr[clip_ct].y=Math.sin(clip_arr[clip_ct].angle*2)*RADIUS + randYOffset;
clip_arr[clip_ct].offsetX = randXOffset;
clip_arr[clip_ct].offsetY = randYOffset;
clip_arr[clip_ct].angle=0;
addChild(clip_arr[clip_ct]);
clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,go);
clip_arr[clip_ct].addEventListener(Event.ENTER_FRAME,cleanUp);
clip_ct++;
}
private function go(evt:Event):void
{
evt.target.scaleX += .05;
evt.target.scaleY += .05;
evt.target.x=Math.cos(evt.target.angle*2)*RADIUS + evt.target.offsetX;
evt.target.y=Math.sin(evt.target.angle*3)*RADIUS + evt.target.offsetY;
evt.target.angle+=.05;
var copy_mc:MovieClip = new Image("smiley.png");
addChild(copy_mc);
copy_mc.scaleX = evt.target.scaleX;
copy_mc.scaleY = evt.target.scaleY;
copy_mc.x=evt.target.x;
copy_mc.y=evt.target.y;
copy_mc.addEventListener(Event.ENTER_FRAME,goCopy);
}
private function goCopy(evt:Event):void
{
evt.target.alpha*=FRICTION;
var blurRate = Math.floor(Math.abs((evt.target.x - stage.stageWidth/2) / 100) * 2);
evt.target.blurImage(blurRate,blurRate);
if(evt.target.alpha<=.3)
{
evt.target.removeEventListener(Event.ENTER_FRAME,goCopy);
var m:MovieClip=evt.target as MovieClip;
removeChild(m);
}
}
private function cleanUp(evt:Event):void
{
if ( evt.target.scaleX >= 3 )
{
evt.target.removeEventListener(Event.ENTER_FRAME,go);
evt.target.removeEventListener(Event.ENTER_FRAME,cleanUp);
var d:DisplayObject=evt.target as DisplayObject;
removeChild(d);
}
}
}
}
a class to load in the image, although if you use this code you should add in a listener to make sure the image is loaded prior to implementing it
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.filters.BitmapFilterQuality;
import flash.filters.BlurFilter;
public class Image extends MovieClip
{
// public properties for the class
public var earl:String;
public var angle = Number;
public var offsetX = Number;
public var offsetY = Number;
public var imgLoader:Loader = new Loader();
private var blur:BlurFilter = new BlurFilter();
public function Image(e:String)
{
earl = e;
// Load in the image
var imgLoader:Loader = new Loader();
imgLoader.load(new URLRequest(earl));
// add image loader
addChild(imgLoader);
}
public function blurImage(blurX:Number=0, blurY:Number=0)
{
blur.quality = BitmapFilterQuality.MEDIUM;
blur.blurX = blurX;
blur.blurY = blurY;
this.filters = [blur];
}
}
}
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.