TextFormat不做任何事情

时间:2011-06-09 19:39:29

标签: flash actionscript-3

我的代码是正确的,但无论如何,无论如何,我的textformat不起作用,请检查以下代码。 没看到我做错了什么。

    //SCROLLING SPEED
var scrolling_speed:int = 2;
//TEXT TO SCROLL

var url:String = "tekst.txt";
var loadit:URLLoader = new URLLoader();
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));

var my_text:TextField = new TextField();
addChild(my_text);

function completeHandler(event:Event):void
{
    my_text.text = event.target.data as String;
}

//set a format
var format:TextFormat = new TextFormat();
//set the color to the hex
//set the font size
format.size = 24;
format.align = "center";
//apply formatting
my_text.setTextFormat(format);

my_text.x = stage.stageWidth = 50, 0;
//set y coord in middle of stage (about)
my_text.y = stage.stageHeight;
//not selectable
my_text.selectable = false;
//no border
my_text.border = false;
my_text.multiline = true;

my_text.textColor = 0xFFFFFF;
//field scales with more text
my_text.autoSize = TextFieldAutoSize.LEFT;



//add the listener to scroll;
my_text.addEventListener(Event.ENTER_FRAME,move_text);

//scroll function;
function move_text(myevent:Event):void
{
    my_text.y -=  scrolling_speed;
    if (my_text.y<(0-my_text.height))
    {
        my_text.y = stage.stageHeight;
    }
}

对于谁不知道

fontsize保持不变或相同。 并且对齐不起作用。 任何帮助都会很精彩

1 个答案:

答案 0 :(得分:3)

而不是my_text.setTextFormat(format);,请尝试my_text.defaultTextFormat = format;