# \[FMX\] Need help with actionscript to loop and fade an image

**URL:** <https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444>\
**Category:** flash\
**Created:** [May 21, 2003, 5:44pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444 "2003-05-21T17:44:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![artfreak](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@artfreak](https://forum.kirupa.com/u/artfreak)\
**Post date:** [May 21, 2003, 5:44pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/1 "2003-05-21T17:44:22Z")

</div>

[AS]onClipEvent(load){  
this.\_alpha=100;  
this.fader=0;  
start = getTimer();  
}

onClipEvent (enterFrame) {  
now = getTimer() - start;  
if (this.fader==1){  
this.\_alpha+=3;  
trace(“fade in”);  
if (this.\_alpha\>=100){  
this.fader=0;  
trace(“stop fade in”);  
}  
}else if (this.fader==2){  
this.\_alpha-=3;  
trace(“fade out”);  
if (this.\_alpha\<=0){  
this.fader=0;  
trace(“stop fade out”);  
}  
}  
if (now\>1000){  
this.fader=1;  
trace(“fader 1”);  
}  
if (now\>4000){  
this.fader=2;  
trace(“fader 2”);  
}  
if (now\>15000){  
start = getTimer();  
trace(“endclip”);  
}  
}

[/AS]  
according to the trace, this is looping, but my clip is not fading back in. As you can see i want it to start at 100%, wait, fade out, wait, start over…but fade in, then loop forever…

Can anyone help Please??

---

<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:** [May 21, 2003, 8:44pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/2 "2003-05-21T20:44:09Z")

</div>

im really a noob at actionscripting but i try to learn by doing some problems that i find in this forum.  
I started to look into yours and i got about the same code as u i belive but mine works fine. the only thing that is something u should be careful about is the fps and getTimer thing. try using fps 20 with my code and u will see it fades down and then stops and then up. but the only problem i see is making it fade down to 0 % and then leting it wait a certain amount of time then fade up to 100 % and then let it wait the SAME amout of time.  
😃  
i dunno if im any help or not but here is the code that works for me. check it out if u like…  
[AS]  
onClipEvent(load){  
this.alpha=100;  
this.fader=0;  
start=getTimer();  
}  
onClipEvent (enterFrame) {   
now=getTimer()-start;  
if(this.fader==1){  
this.\_alpha=this.\_alpha-1;  
timer=timer-1;  
trace(“this.\_alpha-=” + this.\_alpha);  
if(this.\_alpha\<=0){  
this.fader=0;   
}  
}else if(this.fader==2){  
this.\_alpha=this.\_alpha+1;  
trace(“this.\_alpha+=” + this.\_alpha);  
if(this.\_alpha\>=100){  
this.fader=0;  
}  
}  
if(now\>1000){  
this.fader=1;  
//trace(“fader 1”);  
}  
if(now\>8000){  
this.fader=2;  
//trace(“fader 2”);  
}  
if(now\>15000){  
start=getTimer();  
//trace(“endclip”);  
}  
}

[/AS]

as i said, the thing that bugs me is the time interval. i belive its just something with the fps and 1000/8000/15000 numbers, so if u think a bit i bet u get the right interval that u want. 😃

-MZA

---

<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:** [May 21, 2003, 9:13pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/3 "2003-05-21T21:13:36Z")

</div>

how about a new approach? =)

```auto
onClipEvent (load) {
	var alpha = 100, speed = 20, change = function () {
		alpha == 100 ? alpha=0 : alpha=100;
	};
	setInterval(change, 7000);
}
onClipEvent (enterFrame) {
	this._alpha += (alpha-this._alpha)/speed;
}

```

---

<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:** [May 21, 2003, 9:27pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/4 "2003-05-21T21:27:19Z")

</div>

ahh that was lovely! 😃

care to explain some? like for example this :

[AS]alpha == 100 ? alpha=0 : alpha=100;[/AS]

😃

-MZA

---

<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:** [May 21, 2003, 9:35pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/5 "2003-05-21T21:35:04Z")

</div>

i think that basicaly that part checks if alpha is 100 if it is then alpha=0 else alpha=100 -\> a short version of the if statement…

---

<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:** [May 21, 2003, 9:36pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/6 "2003-05-21T21:36:28Z")

</div>

yup… that’s correct, zylum. =)

---

<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:** [May 21, 2003, 9:41pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/7 "2003-05-21T21:41:39Z")

</div>

LOVELY!  
this was for sure what i ment to code too, my fingers just sliped! ;;;;)))))

i think im more glad about your answers then the guy that needed them! HE HE  
😃

thanks guys

-MZA

---

<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:** [May 21, 2003, 9:48pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/8 "2003-05-21T21:48:53Z")

</div>

i’m glad you like it, mza. 😉

---

<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:** [May 21, 2003, 9:49pm UTC](https://forum.kirupa.com/t/fmx-need-help-with-actionscript-to-loop-and-fade-an-image/21444/9 "2003-05-21T21:49:19Z")

</div>

but here is the thing…i have about 15 other movie clips that need to play as well…but they dont need to start until a certain time. Which is why i was doing the timer.

Im including my fla that im working on…and you can kind of see what im talking about. the movie is suppose to loop after 15 sec…which it does…but my clips are not fading back in.

[the fla](http://66.119.16.77/flash/main.fla)  
[the swf](http://66.119.16.77/flash/main.swf)
