View Full Version : how can i stop a function??
nico
April 23rd, 2006, 10:57 AM
i have this title screen with some falling leaves, similar to the snow present here in kirupa. the problem is, when the scene is now in the gameplay, there still some falling leaves, how can i make this function stop.
Nich
April 23rd, 2006, 12:40 PM
The simplest way I can think of is put your code in an if - else statement, with a boolean. Something like:
if(!cutscene)
{
//your snow code
}
else
{
//remove snow
}
Then when you enter the cutscene, set cutscene to true. The code you would use to remove the snow depends on how you're creating it.
nico
April 24th, 2006, 12:10 PM
i get your point, but the code seems to look a bit ahm... un accurate, can u think of another method.
by the way here is the code:
//snow function
snowfall = function () {
width = 800;
// pixels
height = 600;
// pixels
max_snowsize = 10;
// pixels
snowflakes = 50;
// quantity
for (i=0; i<snowflakes; i++) {
x = attachMovie("snow", "snow"+i, i);
x._alpha = 20+Math.random()*60;
x._x = -(width/2)+Math.random()*(1.5*width);
x._y = -(height/2)+Math.random()*(1.5*height);
x._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
x.k = 1+Math.random()*2;
x.wind = -1.5+Math.random()*(1.4*3);
x.onEnterFrame = mover;
}
};
mover = function() {
this._y += this.k;
this._x += this.wind;
if (this._y>height+10) {
this._y = -20;
}
if (this._x>width+20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
} else if (this._x<-20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
}
}
snowfall();
//end of snow function
joe_joe_joe_joe
April 25th, 2006, 08:30 AM
snowflakes = 50;
for (i=0; i<snowflakes; i++) {
removeMovieClip ("snow"+i);
}
That will stop the snow! You must use it in on the same "time line" as the original.
A differerent "frame" of course! ;) Hope that helps!
JOe
www.joe-graphics.com (http://www.joe-graphics.com)
KIERIOSHIMOTO
April 25th, 2006, 10:51 AM
or you could just use unloadMovie
nico
April 25th, 2006, 08:42 PM
thank you very much joex4, you really helped me alot.. also to others who helped me here...
another thing...
how can i make the background scroll, do you want me to show the fla for you t create an engine.???
joran420
April 25th, 2006, 09:47 PM
If you want to pause it just do
mySnowClip.onEnterFrame = null
when you want to stop it and set it back when you want to make it go again
judit
May 28th, 2011, 05:39 AM
Hallo everybody,
I`m a student and new here... So I need some help.
There is a great snowfall AS3-Code on the Site:
http://troyworks.com/blog/2008/11/26/flash-kirupa-snow-in-as30/
Would like to use it in my project, but have a little problem: in my project it has to snow only on Frame 20 (there is a theme about Mountains). If I click to Frame 21 (theme about lowland areas= Amazonas) or whether else in the project, the snow is falling down without stopping. How can I complete the code below to stop the snowfall? Do you have an advice for me?
Thanks in advace for answers and help!
All the best,
Judit
var snowflakes:Array = new Array();
var snowflakeProps:Dictionary= new Dictionary(true);
var max_snowsize:Number = .04;
// pixels
var snowflakesCnt:Number = 150;
var oheight:Number;
var owidth:Number;
init();
function init():void {
owidth = width;
oheight = height;
// quantity
for (var i:int=0; i<snowflakesCnt; i++) {
var t:MovieClip = new SnowFlake();//
t.name = "snowflake"+i;
t.alpha = .2+Math.random()*.6;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);
var o:Object = new Object();
o.k = 1+Math.random()*2;
o.wind = -1.5+Math.random()*(1.4*3);
snowflakeProps[t] = o;
addChild(t);
snowflakes.push(t);
}
addEventListener(Event.ENTER_FRAME, snowFlakeMover);
}
function shakeUp():void{
for (var i:int=0; i<snowflakes.length; i++) {
var t:MovieClip = snowflakes[i] as MovieClip;
t.x = -(owidth/2)+Math.random()*(1.5*owidth);
t.y = -(oheight/2)+Math.random()*(1.5*oheight);
}
}
function snowFlakeMover(evt:Event):void {
var dO:MovieClip;
var o :Object;
if(visible && parent.visible){
for (var i:int = 0; i < snowflakes.length; i++) {
dO = snowflakes[i] as MovieClip;
o = snowflakeProps[dO];
dO.y += o.k;
dO.x += o.wind;
if (dO.y>oheight+10) {
dO.y = -20;
}
if (dO.x>owidth+20) {
dO.x = -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
} else if (dO.x<-20) {
dO.x= -(owidth/2)+Math.random()*(1.5*owidth);
dO.y = -20;
}
}
}
}
Gathan
May 28th, 2011, 06:52 PM
I would assume you put all of that code on the maintimeline, in the example fla all of it was within its only snowmc object, and as long as that existed on only that frame then the snow that was a child of that display object would make it only appear on that frame.
Regardless if you must have it all on the main timeline then make a new function to remove the eventlistener for it and remove all of the snow objects from the stage. Something simple such as this would work just fine.
function removeSnowFlakes():void {
for (var i:int = 0; i<snowflakesCnt; i++) {
this.removeChild(snowflakes[i] as DisplayObject);
}
this.removeEventListener(Event.ENTER_FRAME, snowFlakeMover);
}
Even if you had the snow flakes being added to a snowmc display object instead of the maintimeline, using this would still be recommanded, as you never want to keep eventlisteners, especially strong ones unamanged, even weak ones I never like to leave unremoved.
judit
May 31st, 2011, 03:05 AM
Hello Gathan,
thanks for your answer!
That was quite logical, what you have proposed! I tried to include in the code with your suggestion many times, unfortunately it is still snowing everywhere. Would you please say where should I exactly put your line in the code to make it work?
Can I send you a screenshot of my maintimeline? In the 20. Frame in "action" I have all the code inside. I would like to do, but on your private email address.
Many thanks,
Judit
judit
June 2nd, 2011, 02:45 AM
Good morning Gathan,
I just wanted to thank for your key to stop the snowfall!
For my problem I have already a solution; I have stopped the snow with a Timer. After 20 sec. the snow stops falling. That`s what I wanted. I´m proud that I did, because I haven`t have much programming skills...
Greetings from Munich,
Judit
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.