flash on 2010-8-8

by ruiko
入門サイトよりコピペ
♥0 | Line 33 | Modified 2010-08-08 01:49:27 | MIT License
play

ActionScript3 source code

/**
 * Copyright ruiko ( http://wonderfl.net/user/ruiko )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/h8me
 */

//入門サイトよりコピペ

package
{
    import flash.display.Sprite;
 
    public class Main extends Sprite
    {
        public function Main()
        {
            addChild(Text.textToBitmap(Text.createTextField("abc", 40, 0x0)));
        }
    }
}
 
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
 
class Text
{
    public static function createTextField(text:String, size:int, color:int):TextField
    {
        var tf:TextField = new TextField();
        tf.defaultTextFormat = new TextFormat("_typeWriter", size, color, true);
        tf.text = text;
        tf.autoSize = "left";
        tf.selectable = false;
 
        return tf;
    }
 
    public static function textToBitmap(tf:TextField, transparent:Boolean = true):Bitmap
    {
        var bd:BitmapData = new BitmapData(tf.width, tf.height, transparent, 0x0);
        bd.draw(tf);
 
        return new Bitmap(bd);
    }
}