2010-07-21 27 views
1

我的數組看起來像這樣: var cont1:Array = new Array(「300」,「30」,「1,0FFFF0000,1」,「0xFFFFFF,1」,「yes」,「myFormat」,「200」 ,「200」,「文本」,「10」,「5」,「是」);如何將值傳遞給setTextFormat?

TypeError:錯誤#1034:類型強制失敗:無法將「myFormat」轉換爲flash.text.TextFormat。 at myclass_fla :: MainTimeline/frame1()

即時通訊?將myFormat傳遞給setTextFormat的正確方法是什麼?

+0

爲什麼你會想象字符串「myFormat」應該轉換爲鍵入'flash.text.TextFormat'? – Robusto 2010-07-21 20:27:56

+0

哦對不起我試着不帶引號和它不是工作,那一定是因爲格式設置之後 – Adam 2010-07-21 20:41:04

+0

你應該嘗試的文檔http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/ – 2010-07-21 20:52:17

回答

0

我想你可能有陣的和階級contructors混合起來。

你不能做到這一點:

var cont1:Array = new Array("300","30", "1, 0xFF0000, 1", "0xFFFFFF,1","yes", "myFormat","200","200", "the text", "10","5", "yes"); 
var textFormat : TextFormat = new TextFormat(cont1); //this will throw an error; 

通常你會使用它的類的方法是這樣構建一個TextFormat:

var textFormat : TextFormat = new TextFormat(); 
textFormat.font = "Verdana" 
textFormat.color = 0xFF0000; 
textFormat.size = 10; 
textFormat.underline = true; 

然後將其應用到你的文本框

label.defaultTextFormat = textFormat;