I’m fairly new to AS3, and was rusty with AS2 & 1. I found this cool code on the MathAndFlash site, (see below). Been playing with it. The one thing I can not figure out is how to stop it. I stuck it in a different frame and tried that but it didn’t work. Please, any help in stopping the function without a huge rewrite would be appreciated. Thanks in advance.
stop();
/*
Flash ActionScript 3 Tutorial by Dan Gries.
Please see the accompanying article at www.flashandmath.com for a
discussion of the code.
*/
import com.flashandmath.dg.objects.;
import com.flashandmath.dg.display.;
var origin:Point;
var waitCount:int;
var count:int;
var display:RainDisplay;
var darken:ColorTransform;
var bitmapData:BitmapData;
var bitmap:Bitmap;
var timer:Timer;
var frame:Shape;
var dropsToAddEachFrame:int;
var t:Number;
var spotPositions:Vector.<Point>;
///////////////////////
init();
///////////////////////
function init():void {
//This is how long to wait (in frames) before adding more drops to the stage:
waitCount = 1;
count = waitCount-1;
dropsToAddEachFrame = 9;
origin = new Point(0,0); //to be used with the blur filter.
//This ColorTransform is used to fade out the pictures drawn in the
//animation (instead of erasing them out completely). You can experiment
//with different parameters in this ColorTransform.
darken = new ColorTransform(1,1,1,0.997);
display = new RainDisplay(1004,180,false);
display.defaultDropColor = 0x00162d;
display.randomizeColor = false;
display.defaultDropThickness = 9;
display.splashThickness = 3;
display.defaultDropAlpha = .5;
display.splashAlpha = .5;
display.gravity = 0.1;
//we are using an initial velocity in the downwards direction. Later in the code, the blood drops will
//have "atTerminalVelocity" set to true, so that they will run down at a constant
//velocity rather than accelerate due to gravity.
display.defaultInitialVelocity = new Point(0,.3);
display.initialVelocityVariancePercent = .2;
display.initialVelocityVarianceX=0;
display.initialVelocityVarianceY=0;
display.dropLength = "long";
display.removeDropsOutsideXRange = false;
//The parameters below create drops which "stick" to their initial position
//for a short time before breaking free and falling.
//The variation helps to randomize the timing.
display.globalBreakawayTime = 1;
display.breakawayTimeVariance = 9.5;
//The RainDisplay is actually not displayed on the stage. Instead, it is drawn to
//a bitmap. This method allows for a filter-based fading effect to be used.
bitmapData = new BitmapData(display.displayWidth, display.displayHeight, true, 0x00000000);
bitmap = new Bitmap(bitmapData);
bitmap.x = 4;
bitmap.y = 4;
frame = new Shape();
frame.graphics.lineStyle(1,0x444444);
frame.graphics.drawRect(-1,-1,display.displayWidth+1, display.displayHeight+1);
frame.x = bitmap.x;
frame.y = bitmap.y;
this.addChild(frame);
this.addChild(bitmap);
display.wind = new Point(0,0);
spotPositions = new Vector.<Point>();
findSpots();
this.addEventListener(Event.ENTER_FRAME, onEnter);
}
function findSpots():void {
//This function finds the MovieClips on the stage named “spot*” and records their positions to use
//as blood drop origins. The MovieClips are made invisible.
for (var i:int = 0; i<= this.numChildren - 1; i++) {
var child = this.getChildAt(i);
if (child.name.slice(0,4) == “spot”) {
spotPositions.push(new Point(child.x - bitmap.x,child.y - bitmap.y));
child.visible = false;
}
}
}
function onEnter(evt:Event):void {
var randIndex:int;
//add more raindrops
count++
if (count >= waitCount) {
count =0;
for (var i:int = 0; i <= dropsToAddEachFrame-1; i++) {
randIndex = Math.floor(Math.random()spotPositions.length);
var thisDrop = display.addDrop(spotPositions[randIndex].x+4Math.random()-2,spotPositions[randIndex].y);
//we don’t want these drops to splash when they hit the bottom:
thisDrop.splashing = false;
//we set ‘atTerminalVelocity’ to true so the drops will move down at a constant velocity
//rather than accelerate due to gravity.
thisDrop.atTerminalVelocity = true;
thisDrop.thickness = 4 + 4*Math.random() - 2;
}
}
//update drops
display.update();
//We now draw the rain display to the main bitmap, after applying a ColorTransform
//which causes the previously drawn pictures to fade out.
bitmapData.lock();
bitmapData.colorTransform(bitmapData.rect, darken);
bitmapData.draw(display);
bitmapData.unlock();
}