TextFormat doesn't do anything

社会主义新天地 提交于 2019-12-23 04:27:19

问题


my code is correct, but anyhow, anyway my textformat does not work, examine follow code. Didnt see what i did wrong.

    //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;
    }
}

For who dont know

The fontsize stays little or the same. and the align doesn't work. Any help would be wonderfull


回答1:


Instead of my_text.setTextFormat(format);, try my_text.defaultTextFormat = format;



来源:https://stackoverflow.com/questions/6298284/textformat-doesnt-do-anything

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!