# Optimizing AS fade in/out

**URL:** <https://forum.kirupa.com/t/optimizing-as-fade-in-out/157464>\
**Category:** Uncategorized\
**Created:** [August 2, 2005, 6:39am UTC](https://forum.kirupa.com/t/optimizing-as-fade-in-out/157464 "2005-08-02T06:39:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wagon](https://avatars.discourse-cdn.com/v4/letter/w/e0b2c6/32.png) [@wagon](https://forum.kirupa.com/u/wagon)\
**Post date:** [August 2, 2005, 6:39am UTC](https://forum.kirupa.com/t/optimizing-as-fade-in-out/157464/1 "2005-08-02T06:39:52Z")

</div>

hi guys,

i got some code off flashkit in order to make a photo gallery with a thumbnail grid. there is no XML involved. it mostly works perfectly, however during transitions, the page bogs down considerably and i get choppy fades between the pictures. this is the code for the fading action:

```auto
	// find alpha of new pic
	picalpha = (getProperty(picnum, _alpha));
	// find alpha of old pic
	oldpicalpha = (getProperty(oldpicnum, _alpha));
	// If you want to change fade speed, alter + & - amounts below!
	// if the new pic alpha is 0, fade it up to 100
	if (picalpha<100) {
		setProperty(picnum, _alpha, picalpha +25);
	}
	// if the old pic alpha is 100, fade it down to 0
	if (oldpicalpha>0) {
		setProperty(oldpicnum, _alpha, oldpicalpha -25);
	}
}

```

… i’ve changed the variables bolded

if (picalpha\<100) {  
setProperty(picnum, \_alpha, picalpha **+25** );  
(if (oldpicalpha\>0) {  
setProperty(oldpicnum, \_alpha, oldpicalpha **-25** );

but nothing between 100 and 0 seem to make a nice smooth transition. (well, ok, 1 to 5 make decent transitions but they’re sloooow)

the .fla template file i am basing my gallery on manages the transition nice and smoothly. maybe it is old flash 5 code slowing everything down? (i’m in MX 2004). another interesting thing is that i had to take Math.round out of the original script because it wasn’t recognized.

thanks in advance, i really appreciate it.

ps. here’s the whole script used, which is attached to a movie clip which contains the whole gallery.

```auto
onClipEvent (load) {
	picnum = "one";
	display = "01";
}
onClipEvent (enterFrame) {
	// Feel free to use. Visit Moseleywebb.com
	// find alpha of new pic
	picalpha = (getProperty(picnum, _alpha));
	// find alpha of old pic
	oldpicalpha = (getProperty(oldpicnum, _alpha));
	// If you want to change fade speed, alter + & - amounts below!
	// if the new pic alpha is 0, fade it up to 100
	if (picalpha<100) {
		setProperty(picnum, _alpha, picalpha +25);
	}
	// if the old pic alpha is 100, fade it down to 0
	if (oldpicalpha>0) {
		setProperty(oldpicnum, _alpha, oldpicalpha -25);
	}
}

```

it uses dynamic text variables to load instances. picnum, oldpicnum, and display all refer to dynamic text variables.

this is the code on the buttons:

```auto
on (release) {
	display = "01";
	if (picnum eq "one") {
	} else {
		oldpicnum = picnum;
		picnum = "one";
	}
}

```

whew, long post. thanks again.

---

<div class="post-metadata">

**Author:** ![RaRdEvA](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@RaRdEvA](https://forum.kirupa.com/u/RaRdEvA)\
**Post date:** [April 18, 2006, 3:29pm UTC](https://forum.kirupa.com/t/optimizing-as-fade-in-out/157464/2 "2006-04-18T15:29:34Z")

</div>

I have a Question Related to this. I want to make a background fade effect every X Seconds, but the problem is that is not even close to the S in smooth. Heres the Code:

```auto
function fadingEffect(){
	if(_root.fader_mc._alpha != 0){
	   _root.fader_mc._alpha -= 15;
	   } else if (_root.fader_mc._alpha = 0){
		   	   _root.fader_mc._alpha += 15;
	   }
}

```

I hope someone can help me, i guess it is not hard, but i still cannot understand very well the decrements and increments :wasted:
