Question

Actionscript Bitmap (or BitmapData) is weird. Not only it's cacheAsBitmap is false by default, but it seems BitmapData is not really just a bitmap!

I found out, that animating Text Lines alpha will make them blink. I tried to workaround it in many ways, one of which was drawing text with backgrounds to bitmaps and animating the bitmaps:

package 
{
    import flash.events.Event;
    import flash.display.Sprite;

    import flash.display.Bitmap;
    import flash.display.BitmapData;

    import flash.text.TextField;

    public class Main extends Sprite 
    {
        private var bdata1:BitmapData = new BitmapData ( 150, 50, false, 0xDDDDFF );
        private var bitmap1:Bitmap = new Bitmap( bdata1 );
        private var bdata2:BitmapData = new BitmapData ( 100, 100, false, 0x00FFFF );
        private var bitmap2:Bitmap = new Bitmap ( bdata2 );

        private var show:Boolean = false;

        public function Main():void 
        {
            stage.frameRate = 1;
            var tf:TextField = new TextField ();
            tf.text = "layer top";
            bdata1.draw( tf );
            tf.text = "layer bottom"
            bdata2.draw ( tf );

            //*
            bitmap1.cacheAsBitmap = true;
            bitmap2.cacheAsBitmap = true;
            //*/

            addChild ( bitmap2 );
            addChild ( bitmap1 );
            addEventListener (Event.ENTER_FRAME, onEnterFrame );
        }   

        private function onEnterFrame ( e:Event ):void
        {
            if ( show ) var diff:Number = .2;
            else diff = -.2;

            bitmap1.alpha += diff;
            if ( bitmap1.alpha >= 1 ) {
                show = false;
                bitmap1.alpha = 1;
            }
            else if ( bitmap1.alpha <= 0 ) {
                show = true;
                bitmap1.alpha = 0;
            }
        }
    }
}

What it should do is smoothly (well, if You change the FPS) transition between "Layer bottom" and "Layer top" text. What it does is weird, at least on my machine, showing clearly that the text in bitmap is not treated like a bitmap, but still as a vector (TextLine probably). So is BitmapData only emulating bitmap? Is it a bug? Am I missing something?

Was it helpful?

Solution

First of all, you need to embed Font in swf. Lets assume you have embedded "Arial". Then try this:

var tf:TextField = new TextField ();
var tf_format:TextFormat = tf.defaultTextFormat;
tf_format.font = "Arial";   //Specifying embedded font's name
tf.defaultTextFormat = tf_format; 
tf.embedFonts = true;
tf.antiAliasType = AntiAliasType.ADVANCED;
//.........

After this, you will have 'smooth text'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top