stage.frameRate = 30;
const CIRCLE_RADIUS_MIN:int = 25;
const CIRCLE_RADIUS_MAX:int = 50;
const CIRCLE_SPD:int = 7;
const CIRCLE_CREATION_DELAY:int = 500;
const GRAVITY:int = 5; //Gravity applied to particles ***Added by Calipe***
var maxParticles:int = 10; //Max number of particles
var maxCircles:int = 50;
var circles:Array = new Array(); //lets make a container so we can easily access the circles?
var circleCreationTimer:Timer = new Timer(CIRCLE_CREATION_DELAY, 0);
circleCreationTimer.addEventListener(Tim erEvent.TIMER, createCircleEvent);
circleCreationTimer.start();
function createCircleEvent(timerEvent:TimerEvent)
:void
{
var newCircle:Sprite = createCircleSprite();
newCircle.x = Math.random()*(stage.stageWidth - newCircle.width);
newCircle.y = - newCircle.height;
circles.push(newCircle); //Here we add the circles to the array
newCircle.addEventListener(Event.ENTER_F RAME, onCircleEnterFrame);
newCircle.addEventListener(MouseEvent.MO USE_OVER, mouseDownListener, false, 0, true); //Registers the circle for the mouse over event ***Added by Calipe***
addChild(circles[circles.length - 1]);
}
// this is a method for not polling though an array.
// there is a trade off for this method, using a var for current cirlce
// increases amount of garbage to collect, but this is a light enough app where you dont
// need to worry about that yet. I am going to write an article about local variable and garbage collection.
function onCircleEnterFrame(event:Event):void
{
var currentCircle:Sprite = event.currentTarget as Sprite;
currentCircle.y += CIRCLE_SPD;
if ((currentCircle.y - currentCircle.height) > stage.stageHeight)
{
currentCircle.removeEventListener(Event.
ENTER_FRAME, onCircleEnterFrame); // EXTREMELY IMPORTANT FOR GARBAGE COLLECTION
removeChild(currentCircle);
circles.splice(circles.indexOf(currentCi rcle), 1);
}
}
function createCircleSprite():Sprite
{
var radius:int = CIRCLE_RADIUS_MIN + Math.random()*(CIRCLE_RADIUS_MAX - CIRCLE_RADIUS_MIN);
var tempCircle:Sprite = new Sprite();
tempCircle.graphics.lineStyle();
tempCircle.graphics.beginFill(Math.rando m()*0xFFFFFF);
tempCircle.graphics.drawCircle(radius, radius, radius);
tempCircle.graphics.endFill();
return tempCircle;
}
function getRandomSprite(sourceArray:Array = null):Sprite {
if (sourceArray == null) { //If no array reference is passed to the function...
//Choose any child on the stage to return.
return getChildAt(Math.floor(Math.random() * numChildren)) as Sprite;
} else {
//Return a reference from the specified array
return sourceArray[Math.floor(Math.random() * sourceArray.length)] as Sprite; //Just in case
}
}
//The event listener function that is triggered when the mouse over event is dipatched ***Added by Calipe***
function mouseDownListener(event:MouseEvent):void
{
removeChild(Sprite(event.target));
circles.splice(circles.indexOf(Sprite(ev ent.target)), 1);
event.target.removeEventListener(Event.E NTER_FRAME, onCircleEnterFrame);
createParticles();
}
//Creates the particles ***Added by Calipe***
function createParticles():void
{
for (var i:int = 0; i < maxParticles; i++)
{
var particle:MovieClip = new MovieClip();
particle.graphics.beginFill(Math.random(
) * 0xFFFFFF);
particle.graphics.drawCircle(0, 0, Math.random() * 10 + 5);
particle.vx = Math.random() * 30 - 15;
particle.vy = Math.random() * -50;
particle.x = mouseX;
particle.y = mouseY;
particle.addEventListener(Event.ENTER_FR AME, particleEnterFrame, false, 0, true);
addChild(particle);
}
}
//Particles enter frame listener ***Added by Calipe***
function particleEnterFrame(event:Event):void
{
var tempParticle:MovieClip = MovieClip(event.target);
if ( tempParticle.y < stage.stageHeight)
{
tempParticle.vy += GRAVITY;
tempParticle.x += tempParticle.vx;
tempParticle.y += tempParticle.vy;
}
else
{
removeChild(tempParticle);
tempParticle.removeEventListener(Event.E NTER_FRAME, particleEnterFrame, false);
}
}
attachMovie("ball", "ball", 1)
ball._x = 2000
ball._y = 200
timey = 0
fps = 2
xvel = 9
yvel = 3
xcha =.1
ycha =.1
i = 0
onEnterFrame = function(){
timey ++
if(timey == fps){
dave = _root.attachMovie("blob","blob" + i, _root.getNextHighestDepth())
dave._x = ball._x
dave._y = ball._y
timey = 1.0
i++
}
}
ball.onEnterFrame = function(){
this._x -= xvel
this._y -= yvel
xvel += xcha
yvel -= ycha
if(xvel >= 3 || xvel <= -3){
xcha = -xcha
}
if(yvel >= 3 || yvel <= -3){
ycha = -ycha
}
if(this._x > 500){
this._x = 0
}
if(this._x < 0){
this._x = 500
}
if(this._y > 400){
this._y = 0
}
if(this._y < 0){
this._y = 400
}
}
Hmm... Does that coding fit correclty?