Can anyone pls help me realize what I'm doing wrong here..
goal is to animate particles into letters, and when finally completed to execute removeParticles function which should remove particles from the stage in a same manner they were added. everything works just fine except that last function (when function removeParticles executes flash player begins that 'not responding' behaviour)..any advice welcome..thanx. here's code:
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.MovieClip;
import com.greensock.TweenMax;
import com.greensock.easing.*;
import flash.display.Bitmap;
import flash.events.Event;
[sWF(backgroundColor="0x000000", frameRate="30", width="800", height="200")]
var positions:Array = [];
var SPACING_Y:uint = 3;
var SPACING_X:uint = 3;
var circlesArray:Array = [];
var circleRadius:uint = 3;
var container:Sprite;
mapParticles();
function mapParticles():void
{
container = new Sprite();
addChild(container);
var letters:Letters= new Letters();
container.addChild(letters);
var bmd:BitmapData = new BitmapData(letters.width, letters.height, false, 0xffffff);
bmd.draw(letters);
letters.visible = false;
var rows:int = letters.height / SPACING_Y;
var cols:int = letters.width / SPACING_X;
for(var i:int = 0; i < cols; i++)
{
for(var j:int = 0; j < rows; j++)
{
var pixelValue:uint = bmd.getPixel(i * SPACING_X, j * SPACING_Y);
if(pixelValue.toString(16) != 'ffffff' && pixelValue.toString(16) != '0')
{
positions.push({xpos:i * SPACING_X, ypos:j * SPACING_Y });
}
}
}
shuffle(positions);
generateParticles();
}
function shuffle(arr:Array):void
{
var rand:int;
for(var i:int= 0; i<arr.lenght; i++)
{
var tmp:*= arr[int(i)];
rand= int(Math.random()* arr.length);
arr[int(i)]=arr[rand];
arr[int(rand)]=tmp;
}
}
function generateParticles():void
{
for(var i:int = 0; i < positions.length; i++)
{
var circle = new Sprite()
circle.graphics.beginFill(Math.random()* 0xffffff);
circle.graphics.drawCircle(0, 0, circleRadius);
circle.graphics.endFill();
container.addChild(circle);
circle.x = Math.random() * stage.stageWidth;
circle.y = Math.random() * stage.stageHeight;
circle.alpha = 0;
circlesArray.push(circle);
}
animateParticles();
}
function animateParticles():void
{
for(var i:int = 0; i < circlesArray.length; i++)
{
TweenMax.too(circlesArray,0.5, {
x:positions.xpos,
y:positions.ypos,
alpha: 1,
delay:i * 0.01,
ease:Back.easeOut,
easeParams:[3], onComplete:removeParticles()});
}
}
function removeParticles():void
{
for(var i:int= 0; i<circlesArray.length; i++)
{
TweenMax.to(circlesArray, 1, {
x:Math.random() * stage.stageWidth,
y:Math.random() * stage.stageHeight,
alpha:0,
delay:i* 0.01,
ease:Back.easeIn,
easeParams:[1]});
}
}