纯Flash网站中关于Flash as2技术系列总结
动态创建一个文本框
下面的示例创建一个宽 300,高 100 的文本字段,其 x 坐标为 100,y 坐标为 100,该文本字段有边框,文本为红色并带下划线:
单纯文本
System.useCodepage = true;
this.createTextField("my_txt", this.getNextHighestDepth(), 100, 100, 300, 100);
//设置该文本框相关属性
my_txt.multiline = true;
my_txt.wordWrap = true;
my_txt.border = true;
my_txt.borderColor = 0xff0000;
my_txt.autoSize = "left";
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0xffff00;
my_fmt.underline = true;
my_txt.text = "This is my first test field object text.";
my_txt.setTextFormat(my_fmt);
那么设置TextFormat格式才有效啊;
=====================================================
载入外部的.txt文件
System.useCodepage = true;
this.createTextField("my_txt", this.getNextHighestDepth(), 100, 100, 300, 100);
//设置该文本框相关属性
my_txt.multiline = true;
my_txt.wordWrap = true;
my_txt.border = true;
my_txt.borderColor = 0xff0000;
my_txt.autoSize = "left";
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0xffff00;
my_fmt.underline = true;
//my_txt.text = "This is my first test field object text.";
my_txt.setTextFormat(my_fmt);
var lv:LoadVars = new LoadVars();
lv.onData = function(src:String) {
if (src != undefined) {
my_txt.text = src;
} else {
my_txt.text = "载入不成功";
}
};
lv.load("1.txt");
======================
[/code]新文本字段的默认属性
运行时使用 createTextField() 创建的文本字段接收具有以下属性的默认 TextFormat 对象:
复制内容到剪贴板代码:
align = "left"
blockIndent = 0
bold = false
bullet = false
color = 0x000000
font = "Times New Roman" (default font is Times on Mac OS X)
indent = 0
italic = false
kerning = false
leading = 0
leftMargin = 0
letterSpacing = 0
rightMargin = 0
size = 12
tabStops = [] (empty array)
target = ""
underline = false
url = ""
如果内嵌为段落标签
复制内容到剪贴板代码:
System.useCodepage = true;
this.createTextField("myText", 1, 20, 20, 400, 100);
myText.html = true;
myText.multiline = true;
myText.wordWrap = true;
myText.border = true;
myText.borderColor = 0xff3300;
//myText.backgroundColor=0x00ff00
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0xffff00;
my_fmt.underline = true;
myText.htmlText = "<p align='right'>This text is aligned on the right side of the text field</p>";
不用textFormat方法,,用css 直接写入到flash源文件格式化文本大法
复制内容到剪贴板代码:
System.useCodepage = true;
this.createTextField("myText", 1, 20, 20, 400, 100);
myText.html = true;
myText.multiline = true;
myText.wordWrap = true;
myText.border = true;
myText.borderColor = 0xff3300;
//myText.backgroundColor=0x00ff00
//var my_fmt:TextFormat = new TextFormat();
//my_fmt.color = 0xffff00;
//my_fmt.underline = true;
var myStyle:TextField.StyleSheet = new TextField.StyleSheet();
myStyle.setStyle(".blue", {color:'#339900', fontSize:18});
myText.styleSheet = myStyle;
myText.htmlText = "<p class='blue'>This text is aligned on the right side of the text field</p>";
注释掉textFormat方法..用内部的styleSheet
换行标签
<br> 标签将在文本字段中创建一个换行符。若要使用此标签,您必须将文本字段设置为多行文本字段。
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |