Optimizing AS fade in/out

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:

	// 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.

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:

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

whew, long post. thanks again.

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:

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: