我有一个movieclip,其中我已应用FlashEff2组件来创建文本字段的效果。
但FlashEff2组件会丢弃所有Flash IDE过滤器(GlowFilter)。所以我现在想的是当FlashEff2组件结束其动画内容时添加一个GlowFilter。
但问题是FlashEff2将所有文本拆分成单个字母,导致大量实例。
那么,我怎样才能将这个Glow Filter放到舞台上movieclip txt_mc
内的所有实例中?
谢谢!
答案 0 :(得分:3)
package
{
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BitmapFilter;
import flash.filters.GlowFilter;
import flash.text.TextField;
[SWF(width="500", height="100")]
public class TestEffects extends Sprite
{
private var _letters : Vector.<TextField> = new Vector.<TextField>;
public function TestEffects()
{
super();
// Add some text
var txt_mc : MovieClip = new MovieClip;
for(var i : uint = 0; i < 100; ++i)
{
var l : TextField = new TextField;
l.text = String.fromCharCode( Math.random() * 500 );
l.x = i * 10;
l.y = Math.random() * stage.stageHeight;
txt_mc.addChild( l );
_letters.push(l)
}
addChild(txt_mc);
// Apply a filter on every children
var effect : GlowFilter = new GlowFilter;
applyFilterChildren(txt_mc, effect);
// Just for fun
addEventListener(Event.ENTER_FRAME, updatePosition);
}
public function applyFilterChildren(t : DisplayObjectContainer, effect : BitmapFilter) : void
{
if(!t)
return;
for(var index : uint = 0; index < t.numChildren; ++index)
{
var child : DisplayObject = t.getChildAt( index );
child.filters = [ effect ];
}
}
// Update y position
protected function updatePosition(event:Event):void
{
for each(var l : TextField in _letters)
l.y = (l.y + 1) % 80;
}
}
}
答案 1 :(得分:2)
为什么不直接将GlowFilter添加到容器中?
var glowFilter:GlowFilter = new GlowFilter();
txt_mc.filters = [glowFilter];