# Looping question

**URL:** <https://forum.kirupa.com/t/looping-question/35463>\
**Category:** Uncategorized\
**Created:** [November 14, 2003, 7:36am UTC](https://forum.kirupa.com/t/looping-question/35463 "2003-11-14T07:36:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hga77](https://avatars.discourse-cdn.com/v4/letter/h/4bbf92/32.png) [@hga77](https://forum.kirupa.com/u/hga77)\
**Post date:** [November 14, 2003, 7:36am UTC](https://forum.kirupa.com/t/looping-question/35463/1 "2003-11-14T07:36:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 9:55am UTC](https://forum.kirupa.com/t/looping-question/35463/2 "2003-11-14T09:55:00Z")

</div>

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

```auto
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);
};

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 10:02am UTC](https://forum.kirupa.com/t/looping-question/35463/3 "2003-11-14T10:02:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 10:11am UTC](https://forum.kirupa.com/t/looping-question/35463/4 "2003-11-14T10:11:40Z")

</div>

… Who’s koda? :sleep: 😛

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!). 😛

[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary546.html](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](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary646.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 10:17am UTC](https://forum.kirupa.com/t/looping-question/35463/5 "2003-11-14T10:17:26Z")

</div>

thanks again kode

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 10:18am UTC](https://forum.kirupa.com/t/looping-question/35463/6 "2003-11-14T10:18:39Z")

</div>

No problem. 😉
