Skip to main content
Wesleth
Participant
November 17, 2014
Question

Cant figure out how to stop it snowing... please help :(

  • November 17, 2014
  • 1 reply
  • 523 views

Heya, new ish with flash and actionscript, learning at college and im enjoying it so much im rushing ahead and doing my own thing... thought i would be clever and create a snow effect, alas i cant get it to stop when i want to to, tried all sorts of stop; stopall; commands but its not happening...

Thanks either way for any help

Heres the code im using...

addEventListener (Event.ENTER_FRAME,snow);

function snow (event:Event):void {

   

    var scale:Number=Math.random()*.6;

    var _sf:Snowflake1=new Snowflake1();

    _sf.x=Math.random()*1024;

    _sf.scaleX=scale;

    _sf.scaleY=scale;

    var speed:Number=Math.random()*2;

    var RA:Array=new Array(-1,1);

    var lf:int=RA[Math.round(Math.random())];

    stage.addChild (_sf);

    _sf.addEventListener (Event.ENTER_FRAME,snowfall);

   

    function snowfall (event:Event):void {

       

        _sf.y+=speed;

        _sf.rotation+=Math.random()*20;

        _sf.x+=(Math.random()*2)*lf;

    }

}

Thanks again either way

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 17, 2014

If you remove the first event listener it will stop creating snow.

Wesleth
WeslethAuthor
Participant
November 17, 2014

Thanks for your time, just tried it inside and outside a keyframe later on in frame 970, returns with the message

Scene 2, Layer 'Snow', Frame 1540, Line 11021: Duplicate function definition.

Renamed the function snow and snowfall, left in the snow function and deleted everything else

function snowstop (event:Event):void {

}

Is all im left with now, its still snowing :/

Thankyou

Inspiring
November 17, 2014

As Ned sad, removing the frame listener that calls snow will stop the flake creation. You should also add a test to snowFall so that when y exceeds the stage height the flake will be removed.