# Stopping snow effect AS2 problem

**URL:** <https://forum.kirupa.com/t/stopping-snow-effect-as2-problem/299007>\
**Category:** flash\
**Created:** [October 28, 2009, 2:43pm UTC](https://forum.kirupa.com/t/stopping-snow-effect-as2-problem/299007 "2009-10-28T14:43:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![foot01](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@foot01](https://forum.kirupa.com/u/foot01)\
**Post date:** [October 28, 2009, 2:43pm UTC](https://forum.kirupa.com/t/stopping-snow-effect-as2-problem/299007/1 "2009-10-28T14:43:40Z")

</div>

I have this code that controls snowflakes on stage. It works great but I don’t know how I can stop this when I need to.

I see a “onEnterFrame” but if I try and do a “delete tempFlake.onEnterFrame” on a button…it doesn’t work. That’s the only thing I could think of…any help would be great.

Here’s the code ---- //

//settings

var speed:Number = 2;  
var wind:Number = 0;  
var movieWidth:Number = 550;  
var movieHeight:Number = 400;

createSnow(\_root, 100);

function createSnow(container:MovieClip, numberOfFlakes:Number):Void  
{  
//run a for loop based on numberOfFlakes  
for (var i = 0; i \< numberOfFlakes; i++)  
{

```
    //set temporary variable and attach snowflake to it from the library
    var tempFlake:MovieClip = container.attachMovie("snow_mc", "snow"+container.getNextHighestDepth(), container.getNextHighestDepth());

    //variables that will modify the falling snow
    tempFlake.r = 1+Math.random()*speed;
    tempFlake.k = -Math.PI+Math.random()*Math.PI;
    tempFlake.rad = 0;

    //giving each snowflake unique characteristics
    var randomScale:Number = random(50)+50;
    tempFlake._xscale = randomScale;
    tempFlake._yscale = randomScale
    tempFlake._alpha = random(100)+50;
    tempFlake._x = random(movieWidth);
    tempFlake._y = random(movieHeight);
    
    //give the flake an onEnterFrame function to constantly update its properties        

```

// --------------------- //  
tempFlake.onEnterFrame = function()  
{  
//update flake position  
this.rad += (this.k / 180) \* Math.PI;  
this.\_x -= Math.cos(this.rad)+wind;  
this.\_y += speed;

```
        //if flake out of bounds, move to other side of screen
        if (this._y &gt;= movieHeight) {
            this._y = -5;
        }
        if (this._x &gt;= movieWidth) 
        {
            this._x = 1
        }
        if (this._x &lt;= 0) 
        {
            this._x = movieWidth - 1;
        }
    }

```

//----------------------- //

```
}

```

}
