2014-03-12 33 views
0

我想知道如何在此代碼中將文本格式更改爲Arial或Futura?在ActionScript 3.0中更改TextField的文本格式

在舞臺上有一個名爲my_text的動態文本框,但試圖從屬性面板更改文本不起作用。

這裏是我的代碼:

//SCROLLING SPEED 
var scrolling_speed:int = 10; 
//TEXT TO SCROLL 
var text_to_scroll:String = "This is my text"; 


//establish the field 
var my_text:TextField = new TextField(); 
//add the field to stage 
addChild(my_text); 
//set the text 
my_text.text = text_to_scroll; 
//set the x coord off right side of stage 
my_text.x = stage.stageWidth; 
//set y coord in middle of stage (about) 
my_text.y = (stage.stageHeight/2)-(my_text.height/2); 
//not selectable 
my_text.selectable = false; 
//no border 
my_text.border = false; 
//field scales with more text 
my_text.autoSize = TextFieldAutoSize.LEFT; 

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

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

//scroll function 
function move_text(myevent:Event):void { 
    my_text.x-=scrolling_speed; 
    if(my_text.x<(0-my_text.width)){ 
     my_text.x=stage.stageWidth; 
    } 
} 

回答

0

談到改變字體,請嘗試使用下面的命令:

my_text_format.font = "Arial"; 

my_text_format.font = "Futura"; 

還可以考慮使用的defaultTextFormat財產TextField

//apply formatting 
my_text.defaultTextFormat = my_text_format; 

當您使用setTextFormat()方法時,您只將更改應用於已在表單中的文本。

這裏是你(宋體例如取)的完整代碼:

//SCROLLING SPEED 
var scrolling_speed:int = 10; 
//TEXT TO SCROLL 
var text_to_scroll:String = "This is my text"; 


//establish the field 
var my_text:TextField = new TextField(); 
//add the field to stage 
addChild(my_text); 
//set the text 
my_text.text = text_to_scroll; 
//set the x coord off right side of stage 
my_text.x = stage.stageWidth; 
//set y coord in middle of stage (about) 
my_text.y = (stage.stageHeight/2)-(my_text.height/2); 
//not selectable 
my_text.selectable = false; 
//no border 
my_text.border = false; 
//field scales with more text 
my_text.autoSize = TextFieldAutoSize.LEFT; 

//set a format 
var my_text_format:TextFormat = new TextFormat(); 
//set the color to the hex 
my_text_format.color = 0x000000; 
//set the font size 
my_text_format.size = 24; 
//set the font face 
my_text_format.font = "Arial"; 
//apply formatting 
my_text.defaultTextFormat = my_text_format; 
my_text.setTextFormat(my_text_format); 

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

//scroll function 
function move_text(myevent:Event):void { 
    my_text.x-=scrolling_speed; 
    if(my_text.x<(0-my_text.width)){ 
     my_text.x=stage.stageWidth; 
    } 
} 

更多關於在ActionScript 3.0設置字體:究竟DefaultTextFormat vs SetTextFormat

+0

感謝:ActionScript TextFormat.font values - Erik’s Brain

更多關於defaultTextFormatsetTextFormat()我需要的。你知道也許這是一個XML函數,所以我可以從XML文件或TXT文件中獲取文本數據? – user3391599

+0

@ user3391599,不幸的是,我還沒有得到答案。你的意思是從外部XML文件中獲取一些文本格式數據,以便以後用它來格式化AS3 TextField? –

+0

不只是基本的信息文本,所以我可以很容易地編輯它 – user3391599

相關問題