# Fading images in and out with flash



## Tiansen (Jan 3, 2007)

Hello!

I have a simple Flash animation - fading in and out different images. I have done it with an Actionscript (changing alpha value). That worked ok only on new processors - on all others it eats 100% CPU. I then tried to do it with timeline (motion tween between 2 alpha values of picture). Now it is considerably better, but on CPUs lower than 2 GHz it still eats 100% CPU. Size of animation is 940x160. How can I do this fading correctly so that CPU will not have to do so much calculations?? Please help me!


----------



## Vanquished (Jun 16, 2006)

put the frame rate down?


----------



## Tiansen (Jan 3, 2007)

If I want to get less than 100% CPU utilization on Athlon XP 1800+ I must set FPS below 8. This is unacceptable obviously.


----------



## sfedder (Jul 18, 2007)

this sounds relatively simple and shouldn't take that much horsepower unless you have some other problem occurring. Do you have a link to this animation up somewhere or can you provide the actionscript code you are using to perform the animation? How many layers are being rendered other than the image - are all the images present at once, for example, onscreen or are you bringing in images dynamically - from external files or from the library? Also is the source resolution of the images the same as the resolution being displayed or are the images being scaled dynamically from, say, a larger size?


----------



## Tiansen (Jan 3, 2007)

You can find animations here (made with Flash CS3):

http://www.process.si/banner-slo-timeline2.fla (sample animation with timeline)
http://www.process.si/banner-slo.fla (whole animation with Actionscript)

Timeline version is a little better, but still consumes way too much CPU.


----------



## Jack.Sparrow (Jan 22, 2007)

What if you put a shape over the top of the thing you're trying to fade in and out, and tween that using it's alpha value?


----------



## Tiansen (Jan 3, 2007)

Well, why is that better? If picture is below that shape, computer must still recalculate all pixels of image, when changing alpha of that shape.

Am I missing something?


----------



## Jack.Sparrow (Jan 22, 2007)

Tiansen said:


> Well, why is that better?


 :grin:

I don't know if it's any better, that's just the way I used to do it back in school and the school computers ran it without any issues ...


----------



## sfedder (Jul 18, 2007)

Well big problem with the actionscript is that you are using timer intervals to perform the fade rather than using onEnterFrame to determine the interval. The normal events have much less overhead than the method you are using. Also the method you are using is called much more often than is actually necessary for the frame rate being rendered. Also you have all of the images on the timeline at once and are varying the alphas on a set of stacked images which will cause Flash to have to process them all each time the frame is rendered (because they are physically present in the frame). Also the code is much more complicated than need be. Using a data array to feed a single generic fade sequence routine would result in very little code for this sequence.


----------



## sfedder (Jul 18, 2007)

This seems like a fairly straightforward animation sequence. Have you tried just doing this as a standard animation rather than resorting to unnecessary actionscript? The 2nd flash you posted just shows a single bitmap fade rather than what you are trying to accomplish. Also you have redundant background on some of the images that you would normally separate to reduce the banner size. Is there some reason you are doing this in Flash 5 vs. something from the current decade, lol? You would be better using vector shapes/fonts for some of the elements vs. bitmaps - much more efficient.


----------



## sfedder (Jul 18, 2007)

I ran the "slo-timeline2" animation on a P3-750Mhz cpu and it was only taking about 40% cpu so I donn't know where you are getting 100%cpu on a 2GHz box - perhaps there is something else wrong with the system causing the issue with a normal animation. If you have a complete timeline animation then perhaps it could be looked at for efficiencies.


----------



## Tiansen (Jan 3, 2007)

40% on P3-750 with timeline animation? Well, thats strange. On Athlon XP 1800+ it eats 100%. I tried on other computer with similar horsepower too, but results are similar. Are you running it at original size 940x160?

Yes, timeline animation is only one image fade, because fade operation is operation that causes issues. Although there is only one image on white background without actionscript, it IMHO eats too much CPU.


----------



## sfedder (Jul 18, 2007)

What version of Flash are you publishing with - I am publishing from Flash CS3 Pro - maybe that has something to do with it, although it doesn't make any difference if I publish it for Flash 5 player...

I agree that eating 100% cpu on an Athlon XP 1800+ would be ridiculous but I haven't had the same results. Of course I'm not running it on an Athlon but rather a Pentium (III), but that should not make a difference. The box I was running it on is an old server and does not even have a great graphics card. There must be something else strange about your box that it is eating that much CPU... If that were the case, 95% of the ad banners out there would do the same and there are often multiple many-layered banners running simultaneously on pages... I've been doing flash for many years and have done full-screen flash applications with numerous fades that do not take 100% horsepower. Normally if you are using bitmaps on large screen areas you should try to use lower than 30fps frame rates (normal is 12-15fps). Also I stand by the comments about using timers vs. frame events for animations - too much overhead to be doing timer callbacks that are not synchronized to the frame rate. You are (trying to) recalculate as much as 70-100 times per second at a frame rate that only supports 60fps (which is also set way too high for this type of animation - not necessary.


----------

