flash on 2010-4-27
♥0 |
Line 50 |
Modified 2010-04-27 23:54:53 |
MIT License
archived:2017-03-09 20:20:04
ActionScript3 source code
/**
* Copyright ifep ( http://wonderfl.net/user/ifep )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/deBo
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
public class makeTxtField extends Sprite
{
private var label:TextField = new TextField();
private var str:String = "我輩は猫である。名前はまだない。";
private var tsize:uint = 14;
private var tbold:Boolean = true;
private var tcolor:uint = 0xFF0000;
//makeTxtField( 文字列 , 文字の大きさ , 通常 or 太く , 色 )
public function makeTxtField():void
{
if( !stage )
{
addEventListener( Event.ADDED, addedHandler(str,tsize,tbold,tcolor) );
}
else ScriptBegin(str,tsize,tbold,tcolor);
}
private function addedHandler( str:String,tsize:uint,tbold:Boolean,tcolor:uint ):Function
{
return function(e:Event):void
{
removeEventListener( Event.ADDED, addedHandler );
ScriptBegin(str,tsize,tbold,tcolor);
}
}
public function ScriptBegin(str:String,tsize:uint,tbold:Boolean,tcolor:uint):void
{
with ( label )
{
text = str;
width = 300;
x = 100;
y = 100;
}
var tmpFormat:TextFormat = new TextFormat();
with ( tmpFormat )
{
size = tsize;
bold = tbold; //true or false
color = tcolor;
}
label.setTextFormat( tmpFormat, 0, label.length ); //先頭文字から終端文字まで装飾
stage.addChild( label );
}
}
}