1

I have a movieclip in which i have applied a FlashEff2 component for creating an effect on a text field.

But that FlashEff2 component discards all the Flash IDE Filters (GlowFilter). So what i am thinking now is to add a GlowFilter when FlashEff2 component ends its animation stuff.

But the problem is FlashEff2 breaks apart all the text into single letter which results in lots of instances.

So, how can i put this Glow Filter to all the instances inside the movieclip txt_mc on stage?

Thanks!

Aamir Siddique
  • 334
  • 3
  • 15

2 Answers2

3

enter image description here

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;
        }
    }
}
Simon Eyraud
  • 2,445
  • 1
  • 20
  • 22
2

Why don't you just add the GlowFilter to the container?

var glowFilter:GlowFilter = new GlowFilter();
txt_mc.filters = [glowFilter];
Marty
  • 39,033
  • 19
  • 93
  • 162
  • I wonder how this would affect performance. cacheAsBitmap is turned on automatically when a filter is applied, so one would be applying a filter to a much larger area, and there would be a lot more pixels being processed (mostly white space). Then again, with GPU acceleration, those pixels could be cheap compared to the overhead of having a cache+filter on every single TextField instance, even though fewer pixel would be processed by the shader. I think what you suggest here would be optimal, but it would have to be benchmarked. – Triynko Dec 18 '13 at 21:49
  • Then again, if those letters are moving around, then it might be better to have them individually cached as bitmaps, so that the filter doesn't have to be reapplied as they are moved (unless they are being scaled). For simple translations, it may be more efficient to apply the filter to the individual objects. That would also allow one to assign different colors to each of them, without ever having to recalculate the filter on a container every frame. – Triynko Dec 18 '13 at 21:51
  • @Triynko The question made no reference to performance - if it had, I would have suggested drawing the result of the glowing objects onto a bitmap and using that for rendering instead. – Marty Dec 18 '13 at 21:56