Velocirooster
Velocirooster

Reputation: 646

Optimizing AS3 DropShadowFilter

I'm using GreenSock's TweenMax to fade in a TLFTextField with a DropShadowFilter applied. The framerate drops to about 8fps when I try to do this. Without the shadow, the transition is a consistent 24fps. I know Flash is redrawing the shadow each frame - is there any way I can avoid this?

cacheAsBitmap seems to have no noticeable effect. I could draw the textfield to a bitmap, but I'd like that to be a last resort. Is there any override for redrawing the shadow? Or perhaps an alternative method?

Any help would be appreciated. Thanks in advance.

Upvotes: 0

Views: 99

Answers (1)

Vesper
Vesper

Reputation: 18757

Embed the TextField to fade in into a parent Sprite, cache that sprite as bitmap, and fade the parent in by tweening its alpha. This should make Flash draw the drop shadow only once per entire processing.

var fadeholder:Sprite=new Sprite();
fadeholder.addChild(tf); // your textfield
tf.alpha=1;
// it should have filter applied already
fadeholder.cacheAsBitmap=true;
addChild(fadeholder);

After you do this, initiate tween on fadeholder.alpha, and once it's over, add the textfield to a proper parent ("this", maybe) and remove the obsolete fadeholder from display list.

Upvotes: 1

Related Questions