Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
If you remove the first event listener it will stop creating snow.
Copy link to clipboard
Copied
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 1 | 1021: 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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
If that is all you have then it will do nothing to stop the snow. When you added the event listener you used...
addEventListener (Event.ENTER_FRAME,snow);
so to remove that event listener you use...
removeEventListener (Event.ENTER_FRAME,snow);