2 Replies Latest reply on Nov 18, 2009 11:36 AM by iggyotis22

    make snow fall inside a movieclip

    iggyotis22

      Hi,

       

      I have some code which makes snow fall perfectly, but I want it to only happen inside a movieclip (a snowglobe to be exact). Any ideas how I could make this happen?

       

      var speed:Number = 5;
      var total_snow:Number = 200;
      var snow_per_second:Number = 3
      var hit_target:MovieClip = gazing_mc
      //
      var holder:Sprite = new Sprite();
      var target_shake:Boolean = false;
      //
      addChild(holder);
      //
      hit_target.mainX=hit_target.x;
      hit_target.mainY=hit_target.y;
      //
      function createSnow() {
      var snow:MovieClip = new MovieClip();
      snow.graphics.beginFill(0xFFFFFF);
      snow.graphics.drawCircle(0,0,Math.random()*2);
      reset(snow);
      addBlur(snow);
      snow.addEventListener(Event.ENTER_FRAME,fall);
      holder.addChild(snow);
      }
      function reset(s:MovieClip) {
      s.hit=s.shake=false;
      s.y=0;
      s.x=Math.random()*800;
      s.xspeed=Math.random()*speed-(speed/2);
      s.yspeed=Math.random()*speed+1;
      }
      function init(e:Event) {
      for(var i=0; i<snow_per_second; i++) {
      createSnow();
      }
      snow_id++;
      if(snow_id>total_snow) {
      removeEventListener(Event.ENTER_FRAME,init);
      }
      }
      function addBlur(s:MovieClip) {
      var blurX:Number = Math.random()*2+3;
      var blurY:Number = Math.random()*2+3;
      var filter:BitmapFilter = new BlurFilter(blurX, blurY, BitmapFilterQuality.LOW);
      var myFilters:Array = new Array();
      myFilters.push(filter);
      s.filters = myFilters;
      }
      function fall(e:Event) {
      if (!e.target.hit) {
      e.target.x+=e.target.xspeed;
      e.target.y+=e.target.yspeed;
      if (e.target.y>600) {
      reset(MovieClip(e.target));
      }
      if(!e.target.shake) {
      if (hit_target.hitTestPoint(e.target.x,e.target.y,true)) {
      e.target.hit=true;
      }
      }
      }else{
      if(target_shake) {
      e.target.hit=false
      e.target.shake=true;
      }
      }
      }
      function shake_int(e:TimerEvent) {
      hit_target.x=hit_target.mainX+Math.random()*5-2.5;
      hit_target.y=hit_target.mainY+Math.random()*5-2.5;
      }
      var shake_timer:Timer = new Timer(2,100);
      shake_timer.addEventListener(TimerEvent.TIMER,shake_int);
      shake_timer.addEventListener(TimerEvent.TIMER_COMPLETE,shake_fnish);
      function shake_fnish(e:TimerEvent) {
      target_shake=false;
      }
      //
      hit_target.addEventListener(MouseEvent.CLICK,shake_start);
      function shake_start(e:Event) {
      target_shake=true;
      shake_timer.reset();
      shake_timer.start();
      }
      //
      var snow_id:int = 0
      addEventListener(Event.ENTER_FRAME,init);