Web Design Forum: Killing a function in AS2 - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Killing a function in AS2 Rate Topic: -----

#1 User is offline   jwalker80 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 23-June 09
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 15 December 2011 - 03:54 PM

Hi,

I am looking to kill this script out after a certain length of time...

	init = function () {
	width = 728;
	// pixels 
	height = 90;
	// pixels 
	max_snowsize = 30;
	// pixels 
	snowflakes = 30;
	// quantity 
	for (i=0; i<snowflakes; i++) {
		t = attachMovie("snow", "snow"+i, i);
		t._alpha = 50+Math.random()*60;
		t._x = -(width/2)+Math.random()*(1.5*width);
		t._y = -(height/2)+Math.random()*(1.5*height);
		t._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
		t.k = 1+Math.random()*2;
		t.wind = -1.5+Math.random()*(1.4*3);
		t.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;
	}
}
init();


Does anyone know how I would go about doing this?
0

#2 User is offline   NickTheGreat 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 27
  • Joined: 01-January 12
  • Reputation: 4
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 01 January 2012 - 09:02 AM

I'm not sure... but try something like this

var timer;
function onLoad()
{
timer = 0;
}
function onEnterFrame(){
timer += 1;
}

if(timer > 30){
//leave blank, or alternate code
}
else{
//code to be killed
}

if the fps is 30, this will kill the code after 30 frames (1 second) because the var "timer" goes up 1 every frame, and the code will only happen if the timer is less than 30. You can adjust the "30" to fit your need.
if you want to reset you could add
if(timer > *reset time*){
timer = 0;
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users