text to bitmap

Some time ago i wanted to create some scrolling text in flash, it was a clients idea not mine i had advised against it but as these things go they usually ignore the advice. Anway originally i had a simple textfield and moved it along the x axis, this all seemed to work ok but i noticed that the timing of the scrolling would change it would become faster and slower depending on what your mouse is doing. I’m not sure if that was because of the particular computer i was using the browser or maybe some shoddy coding, regardless i decided that creating the text as a bitmap would be a better idea and thought it might solve some problems which it did at the time. So here is what i did, the main thing to note is that the textfield is created by is never added to the displaylist it is used purley as the source for the bitmap and then the bitmap is added to the stage.

var s:String = "this is a test string";
// create your textfield
var txtField:TextField = new TextField();
txtField.width = 150;
txtField.height = 20;
txtField.embedFonts = true;
txtField.selectable = false;
txtField.autoSize = TextFieldAutoSize.LEFT;
txtField.defaultTextFormat = new TextFormat( "Verdana", 12, 0xFF0000 );
// copy the textfield into bitmapdata
var bitdata:BitmapData = new BitmapData( txtField.width + 1, txtField.height + 1, true, 0x585657);
bitdata.draw( txtField );
// create your bitmap
var bitmap:Bitmap = new Bitmap( bitdata );
// now add the bitmap to stage
addChild( bitmap );

Comments

    Comments are currently closed