Ok... here's an fla:
http://www.mediafire.com/?xmm5jzyb3qmIts structure is as follows:
On the main timeline:
-2 layers, a layer for the black background and a layer for the snow
-300 frames
-keyframes on snow layer on frames 1, 101 and 201
The following actions are added for the snow_mc movieclip on frame 1:
snowflakes = 100;
do {
duplicateMovieClip(snow, "snow"+k, k);
k++;
} while (k != snowflakes);
On frames 101 and 201, the # of snowflakes changes to 101 and 102.
The following code is attached to frame 1 on the snow layer:
this.onEnterFrame = function() {
if (!(this._currentframe >= 1 && this._currentframe<=100)){
snow_mc.gotoAndStop(1);
} else if (!(this._currentframe >= 101 && this._currentframe<=200)){
snow_mc.gotoAndStop(2);
} else {
snow_mc.gotoAndStop(3);
}
}
Inside the snow_mc movieclip, there is another movieclip named "snow", inside of which is the small .png image which is the snowflake.
There are 3 keyframes inside the snow_mc movieclip. To the "snow" movieclip on the 1st keyframe, the following code is attached:
onClipEvent (load) {
//variables
width = 600;
height = 429;
//random x,y, and alpha
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 20+Math.random()*50;
//random x and y for flakes
this._x = -width+Math.random()*(3*width);
this._y = -10+Math.random()*height;
//speed and trigonometric value
i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;
rad = 0;
}
onClipEvent (enterFrame) {
// horizontal movement
rad += (k/180)*Math.PI;
xmovement = width * 0.5;
this._x -= Math.cos(rad)+(xmovement-(width/2))/50;
// vertical movement
this._y += i;
// remove clips when they misbehave (overstep boundaries)
if (this._x>(width+50)) {
this._x = -45;
this._y = Math.random()*height*2;
}
if (this._x<-50) {
this._x = width+45;
this._y = Math.random()*height*2;
}
if (this._y>=height) {
this._y = -50;
this._x = -width+Math.random()*(3*width);
}
}
On keyframes 2 and 3, it's the same thing except on frame 2:
xmovement = width * 1.5;
and on frame 3:
xmovement = -width * 1.5;
This value controls the direction of the wind. "width * 0.5" is 0, so it should be obvious when the movieclip moves to frames 2 or 3.
When I try to make a .swf from this, Flash MX gives me the following error message:
Scene=Scene 1, Layer=Layer 2, Frame=201: Line 2: Statement must appear within on/onClipEvent handler
do {
P.S. I got a PM from glosrfc on another forum, part of which I will repost here with some comments:
I did say that you need to check the currentframe inside an onEnterFrame handler. The syntax on the main timeline is:
this.onEnterFrame = function() {
// code to check _currentframe here
}
Ok... I hope I did that right in the code I just posted. Though it seems to be giving me errors.
One of the problems you seem to have is controlling all of the different timelines that are running. For example, if you have a snow mc referenced with this...what does this refer to when you swap the first snow mc for a second snow mc? That's one of the reasons why it's recommended that all code is placed on the main timeline rather than placed directly onto movieclips.
So if "this" is a problem (though it seemed to work when there were just two keyframes in the movieclip), what's the alternative?
Finally, did you have any joy with the idea about passing your variables into the movieclips, instead of hardcoding them into the movieclips themselves? There are a few reasons why this approach is preferable:
1. You can control the variables from the main timeline without having to check which frame the playhead is currently on.
2. You don't have to edit (and then remember) different settings inside different MCs
3. You can use multiple instances of a single MC rather than create new MCs for each different variable..this will reduce the overall size of the final SWF.
4. Using instance names makes it simpler to target your symbols.
Well, it seems that I can already change the # of snowflakes by making new keyframes on the snow layer in the main timeline. What I really need to be able to do is to change the windspeed (which is controlled by that "xmovement" parameter in the movieclip). Is it possible to move that parameter into the main timeline, and if so, could someone make an example .fla?