The second method you posted doesn't work, as Snowflakes isn't initialised on the first run through so it errors as Snowflakes is undeclared.
As for your first idea, I'm going to try it now, although this whole Flash scenario is new to me - I'm used to Java, C++ and the like.
EDIT: Does anyone have any good links on how to do this? I honestly have absoloutely no idea how to do this.
Ah, good to know you have some coding knowledge, that gives me some more freedom
.
Hm, that's odd, are you sure you put the exclamation mark (!) in front of "snowFlakes" in the conditional statement? Because "if (!snowFlakes)" literally means "if there is no variable called snowFlakes" (well technically it could also mean "if snowFlakes is set to false", but only if snowFlakes had been declared as a Boolean earlier on). Also, it sure works here XD. I'll just post the entire thing again, that way there's no room for misinterpretation:
CODE//***COMMENCE THY SNOWING!***//
stop(); //makes sure this frame keeps looping;
stage.quality = "high"; //sets the quality to high, value can also be StageQuality.HIGH (but this is obviously shorter);
stage.align = "topLeft"; //sets the stage to stick to the top left upon being resized, value can also be StageAlign.TOP_LEFT;
stage.scaleMode = "noScale"; //makes sure the stage does not scale automatically upon being resized, value can also be StageScaleMode.NO_SCALE;
//***SETUP***//
var flakeAmnt:int = 150; //amount of snowflakes;
var flakeSize:Number; //for randomization of flake size later in code;
var minFlakeSize:Number = 1.5; //minimal flake size (for randomization);
var maxFlakeSize:Number = 4.5; //maximum flake size (for randomization);
var avgSpeedY:Number = 1; //average vertical fall speed;
var deviationY:Number = 1.5; //maximum deviation from average vertical speed;
var avgSpeedX:Number = 0; //average horizontal speed (use a negative number to make more flakes go to the left);
var deviationLeft:Number = 1.5; //maximum deviation from average horizontal speed, towards the left;
var deviationRight:Number = 1.5; //maximum deviation from average horizontal speed, towards the right;
if (!snowFlakes){
var snowFlakes:Array = []; //Array to be filled with snowflakes;
//***FLAKE CREATION***//
for (var i:int = 0; i < flakeAmnt; i++){ //this loop creates all snow flakes, one per iteration;
flakeSize = rndBetween(minFlakeSize, maxFlakeSize); //determine size for this flake;
snowFlakes
= new MovieClip(); //create a new MovieClip in a new spot in the Array that corresponds to the current iteration's number (i), for the flake to be in;
addChild(snowFlakes); //add the MovieClip to the stage so that it shows up;
snowFlakes.graphics.beginFill(0xFFFFFF, rndBetween(.3,1)); //begin a white (0xFFFFFF is hexadecimal for RGB white) fill for drawing a snow flake into the previously created MovieClip;
snowFlakes.graphics.drawCircle(0,0,flakeSize); //draw a snow flake (a simple circle) around the (0,0) coordinate of the MovieClip, using the size (flakeSize) we determined at the beginning of the loop;
snowFlakes.graphics.endFill; //end fill for the snow flake;
snowFlakes.flakeBlur = new BlurFilter; //create a new BlurFilter instance;
snowFlakes.flakeBlur.quality = 2; //set the BlurFilter's quality to 2 (which is like medium, I wouldn't generally recommend going above 3 since it can get pretty heavy);
snowFlakes.flakeBlur.blurX = snowFlakes.flakeBlur.blurY = rndBetween(1,8); //set the BlurFilter's horizontal and vertical blur values to the same random value;
snowFlakes.filters = [snowFlakes.flakeBlur]; //apply the filter to the flake;
snowFlakes.fallSpeedY = rndBetween(Math.abs(avgSpeedY-deviationY),Math.abs(avgSpeedY+deviationY)); //determine vertical fall speed according to the variables we set in the setup at the top, using the rndBetween function at the bottom;
snowFlakes.fallSpeedX = rndBetween(avgSpeedX-deviationLeft,avgSpeedX+deviationRight); //same thing, this time for horizontal speed;
snowFlakes.x = rndBetween(0,stage.stageWidth); //placement of flake at random horizontal coordinate on stage;
snowFlakes.y = rndBetween(0,stage.stageHeight);//placement of flake at random vertical coordinate on stage;
}
}
//***FLAKE ANIMATION***//
addEventListener(Event.ENTER_FRAME, fH); //event listener that fires every time the movie enters a new frame, attached to the fH function (acronym for frameHandler), this is ideal for scripted animation;
function fH(e:Event):void { //the function that gets executed every time the event that it is linked to fires;
for (var j:int = 0; j < flakeAmnt; j++){ //another loop, this time it goes through the entire array that contains the snow flakes, to move each flake to its next position;
snowFlakes[j].x += snowFlakes[j].fallSpeedX; //add the flake's horizontal fall speed (which we determined earlier on) to its current place on the horizontal (x) axis, effectively moving it horizontally;
snowFlakes[j].y += snowFlakes[j].fallSpeedY; //same thing, only for the vertical (y) axis. This can't be negative since that would make the snow fly upwards ;
//***this segment is for keeping the flakes on the stage, they get "recycled" every time they go out of view***//
if (snowFlakes[j].y > stage.stageHeight+(snowFlakes[j].height/2)){ //if the flake goes completely out of view on the bottom...
snowFlakes[j].y -= stage.stageHeight+snowFlakes[j].height; //make it go all the way to the top so that it shows up again next iteration!
}
if (snowFlakes[j].x > stage.stageWidth+(snowFlakes[j].width/2)){ //same thing, only for the right side...
snowFlakes[j].x -= stage.stageWidth+snowFlakes[j].width; //and here we move it to the left...
}
if (snowFlakes[j].x < 0-(snowFlakes[j].width/2)){ //and this one's for the left side...
snowFlakes[j].x += stage.stageWidth+snowFlakes[j].width; //and we move it to the right.
}
//***end of recycling segment. Note that of the last two parts (which deal with the left and right sides), only one is ever applicable to the current flake since a flake moving to the left never goes off the stage on the right side***//
}
}
//***SIMPLE FUNCTION FOR RANDOMIZING BETWEEN TWO NUMBERS***//
function rndBetween(min:Number, max:Number) { //take the numbers we got from the call to this function (for example if we put "rndBetween(1,2)" somewhere);
return((Math.random()*(max-min))+min); //use Flash's own Math.random() function to generate a random number between 0 and 1,
//then multiply that with the maximum we got from the call *minus* the minimum. This
//will result in a number between 0 and said maximum minus minimum. Now, we add the minimum
//to this number and we end up with a number between the minimum and the maximum!
}