Flash MX 2004 內建支援部分 HTML 標籤,讓開發者能在文字欄位中套用豐富排版,大幅提升設計靈活性。本文整理所有支援標籤的屬性與實作範例,助您快速掌握核心用法。
將文字加粗顯示,語法簡單直接。
my_txt.htmlText = "<b> Bold </b>";
套用斜體效果,適合強調或引用內容。
my_txt.htmlText = "<i> Italic </i>";
為文字添加底線裝飾。
my_txt.htmlText = "<u> Underline </u>";
強制換行,不需關閉標籤。
my_txt.htmlText = "Title of Articles <br>";
支援三大核心屬性:
my_txt.htmlText = "<font color='#ff0000' face='Arial' size='12'>This is a text</font>";
建立獨立段落,支援對齊與 CSS 類別:
my_txt.htmlText = "<p align='right' class='title'>align right</p><p align='left' class='body'>align left</p>";
注意:文字欄位需啟用「多行」選項,且 CSS 類別需預先定義。
針對區塊內文字套用 CSS 樣式,需搭配 CSS 物件使用。
my_txt.htmlText = "<span class='body'>this is a text confined by css</span>";
建立無序列表,同樣需要「多行」模式。
my_txt.htmlText = "Sports:<li>Football</li> <li>Boxing</li><li>Swimming</li>";
不僅能插入 JPG 圖片,還支援 SWF 動畫與 MovieClip 實例。
核心屬性:
重要提醒:Flash 不支援漸進式 JPG 格式。
直接套用 TextFormat 物件屬性,實現專業排版:
\t 實現表格對齊tabField = "<b>Name Sex Age </b><br>"; tabRecord1 = "Jinni\t20\tMale<br>"; tabRecord2 = "Sucy\t21\tFemale<br>"; txt = "<textformat tabstops='[50,150,150]'>" + tabField + tabRecord1 + tabRecord2 + "</textformat>";