Hi!
I’m doing my daily homework at Flashkit, in order to see how other people do certain things. This helps me a lot by seeing different ideas and code structures.
It was just the other day when I downloaded the “Fade script image gallery” by Ben Durman, when I stepped into an unsusual? behaviour that I can’t get to understand.
It’s very simple, in the gallery there are 10 pictures. Everytime you click in one number, the previous image fades out and the new image fades in. The AS code is very simple and easy to understand. However, why I can’t possibly understand is that when I create a new layer with another image, the whole movie starts to statter, transitions are not smooth any longer and some transitions are not even properly executed. The more layers/pictures I add, the worse it all gets (15 pics is almost impossible to handle).
I made some modifications in order to improve it, but it was useless (although I keep on thinking that I should have helped!).
Part of the original code which makes transition between pictures happen is this:
[AS]
onClipEvent (enterFrame) {
// find alpha of new pic
picalpha = Math.Round(getProperty(picnum, _alpha));
// find alpha of old pic
oldpicalpha = Math.Round(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 + 5);
}
// if the old pic alpha is 100, fade it down to 0
if (oldpicalpha >0) {
setProperty(oldpicnum, _alpha, oldpicalpha - 5);
}
}
[/AS]
The slightly modified code by me is this.
[AS]
onClipEvent (enterFrame) {
// find alpha of new pic
picalpha = Math.Round(getProperty(picnum, _alpha));
// find alpha of old pic
oldpicalpha = Math.Round(getProperty(oldpicnum, _alpha));
// If you want to change fade speed, alter + & - amounts below!
this.onEnterFrame = function(){
// if the new pic alpha is 0, fade it up to 100
if (picalpha <100) {
setProperty(picnum, _alpha, picalpha + 5);
} else {
delete this.onEnterFrame;
}
// if the old pic alpha is 100, fade it down to 0
if (oldpicalpha >0) {
setProperty(oldpicnum, _alpha, oldpicalpha - 5);
} else {
delete this.onEnterFrame;
}
};
}
[/AS]
For those of you who are curious about it and want to help me find out what’s going on, here’s the original file and my modified file with 2 additional pictures on it.
Let’s see if we can understand Flash behaviour a little bit more by finding an answer to this.
Thank you very much for your interest.
Manare