I’m interested in adding a loop to some falling leaves, so a group of leaves fall, there’s a delay and then another group of leaves fall, and then this will repeat.
Any help would be much appreciated!
Here’s the code I have at the moment:
package
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
public class Main extends MovieClip
{
private var clips_array:Array;
private const SPRING:Number=.1;
private var timer:Timer;
public function Main()
{
init();
initTimer();
}
private function init():void
{
stage.frameRate=22;
clips_array=new Array(mc_clip_0,mc_clip_1,mc_clip_2,mc_clip_3,mc_clip_4,mc_clip_5);
}
private function initTimer():void
{
timer=new Timer(700,0);
timer.addEventListener(TimerEvent.TIMER,go);
timer.start();
}
private function go(evt:TimerEvent):void
{
var n:Number=Math.floor(Math.random()*clips_array.length);
var clip:MovieClip=new clips_array[n];
clip.x=Math.random()*600/*stage.stageWidth;*/
clip.y=-clip.height;
clip.center=clip.x;
clip.vel_x=2+Math.random()*10;
clip.vel_y=clip.vel_x;
clip.angle=0;
addChild(clip);
clip.addEventListener(Event.ENTER_FRAME,goDown);
}
private function goDown(evt:Event):void
{
var acc_x:Number=(evt.target.center-evt.target.x)*SPRING;
evt.target.vel_x+=acc_x;
evt.target.x+=evt.target.vel_x;
evt.target.y+=15-evt.target.vel_y;
evt.target.rotation++;
var sine:Number=Math.sin(evt.target.angle);
evt.target.scaleX=sine;
evt.target.angle+=.1;
if(evt.target.y>=stage.stageHeight+100)
{
evt.target.removeEventListener(Event.ENTER_FRAME,goDown);
var m:MovieClip=evt.target as MovieClip;
removeChild(m);
}
}
}
}