Looping question

what am I doing wrong???

currentThumb.onRollOver = currentThumb.onDragOver = function(){
this._alpha = 40;

}
currentThumb.onRollOut = currentThumb.onDragOut = function(){
while (alpha < 100){
alpha+=1;
this._alpha = alpha;
}

}

what im trying to do:

onRollover the alpha changes to 30. onRollout the alpha changes to 100 in steps. ie. fading in

please help

Use an [font=courier new]onEnterFrame[/font] handler or [font=courier new]setInterval[/font] instead of the [font=courier new]while[/font] statement. :slight_smile:

function fadein() {
	this._alpha = Math.min(100, ++this._alpha);
	if (this._alpha == 100) {
		delete this.onEnterFrame;
	}
}
currentThumb.onRollOver = function() {
	this._alpha = 30;
};
currentThumb.onRollOut = function() {
	this.onEnterFrame = fadein;
};
//
function fadein() {
	currentThumb._alpha = Math.min(100, ++currentThumb._alpha);
	if (currentThumb._alpha == 100) {
		clearInterval(intervalid);
	}
}
currentThumb.onRollOver = function() {
	this._alpha = 30;
};
currentThumb.onRollOut = function() {
	intervalid = setInterval(fadein, 1000/12);
};

thanks koda…

im a c++programmer and im trying to learn AS. Could you be so kind and explain how come we have two functions with the same name and why do we need onenterframe and clearinterval???

thanks

… Who’s koda? :sleep: :stuck_out_tongue:

You don’t need them both, either use the [font=courier new]onEnterFrame[/font] handler (you should use a movie clip, not a button) or the [font=courier new]setInterval[/font] (you can use a movie clip or a button) function. These are used to call the function constantly.

And we have two functions with the same name because I posted an example on how to do it by using an [font=courier new]onEnterFrame[/font], and another one using [font=courier new]setInterval[/font] (separated by the comment line!). :stuck_out_tongue:

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary546.html
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary646.html

thanks again kode

No problem. :wink: