I have battled through several tutorials to come up with the perfect particle snow effect. The only thing I need to do now is duplicate the particle effect and have a second version of it play between my background and foreground. The original I still want to keep as the top most layer. I tried wrapping the code in a function and making two of them with different names, but I got a bunch of weird errors. So instead of ruining what I already have I came here to ask for any advice on the situation. Here is my code. I am using the Greensock animation library to handle my timeline and animation.
import com.greensock.*;
import com.greensock.easing.*;
addChildAt(MC_BG, 0)
addChildAt(MC_FG, 2)
var tl:TimelineMax=new TimelineMax({paused:false});
function createFlake(offset) {
//create a flake (attach symbol in library with Class flake) and position on stage
var flake:Flake = new Flake();
flake.y=-50;
flake.x=randomRange(-10,1090);
flake.alpha=0;
addChild(flake);
//create timeline for each flake
var nestedTl:TimelineMax = new TimelineMax();
//how much wiggling / zig zagging
var wiggle:Number=randomRange(15,35);
//zig or zag?
wiggle=Math.random() > .5?- wiggle:wiggle;
//how fast and big
var speed:Number=randomRange(5,15);
//fade and grow
nestedTl.insert(TweenMax.to(flake, .5, {alpha:randomRange(.5,1), scaleX:speed, scaleY:speed}));
//go down
nestedTl.insert(TweenMax.to(flake,speed, {y:800}));
//zig zag
nestedTl.insert(TweenMax.to(flake, speed*.15, {x:String(wiggle), repeat:Math.floor(randomRange(1,4)), yoyo:true, ease:Sine.easeInOut}));
tl.insert(nestedTl, offset);
}
//generate random num between a min and max value
function randomRange(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}
function init() {
//create a bunch of flakes and add them to timeline
for (var count:Number = 0; count<10000; count++) {
var offset = count * 0.075;
createFlake(offset);
}
}
init();
Any help would be greatly appreciated.
The answer was so simple I completely overlooked it. I made 3 blank Movie Clips, and in each of them I put a slightly modified version of this code. Then I put each movie clip on a layer in between what I wanted, and Bob's your uncle, it worked.