TextField实例
1.TextEield显示HTML及基本用法
package
{
import flash.display.Sprite;
import flash.text.*;
public class TextFieldApp extends Sprite
{
private var myTextBox:TextField = new TextField();
private var myText:String = "<p>This is <b>some</b> content to <i>render</i> as <u>HTML</u> text.</p>";;
public function TextFieldApp()
{
addChild(myTextBox);
myTextBox.htmlText = myText;
myTextBox.border = true;
myTextBox.borderColor = 0xFF0000;
myTextBox.wordWrap = true;//自动换行
myTextBox.width = 150;//控件宽
myTextBox.height = 40;//控件高
myTextBox.x = 100; //控件位置
myTextBox.y = 100 //控件位置
}
}
{
import flash.display.Sprite;
import flash.text.*;
public class TextFieldApp extends Sprite
{
private var myTextBox:TextField = new TextField();
private var myText:String = "<p>This is <b>some</b> content to <i>render</i> as <u>HTML</u> text.</p>";;
public function TextFieldApp()
{
addChild(myTextBox);
myTextBox.htmlText = myText;
myTextBox.border = true;
myTextBox.borderColor = 0xFF0000;
myTextBox.wordWrap = true;//自动换行
myTextBox.width = 150;//控件宽
myTextBox.height = 40;//控件高
myTextBox.x = 100; //控件位置
myTextBox.y = 100 //控件位置
}
}
}
对应的swf文件
/Files/dreamcs/TextFieldApp_1.swf
alwaysShowSelection属性
选择文件后,失去输入焦点时,仍高亮显示以前选中的文字。
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_alwaysShowSelection extends Sprite {
public function TextField_alwaysShowSelection() {
var label1:TextField = createCustomTextField(0, 20, 200, 20);
label1.text = "This text is selected.";
label1.setSelection(0, 9);
label1.alwaysShowSelection = true;
var label2:TextField = createCustomTextField(0, 50, 200, 20);
label2.text = "Drag to select some of this text.";
}
private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x; result.y = y;
result.width = width; result.height = height;
addChild(result);
return result;
}
}
}
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_alwaysShowSelection extends Sprite {
public function TextField_alwaysShowSelection() {
var label1:TextField = createCustomTextField(0, 20, 200, 20);
label1.text = "This text is selected.";
label1.setSelection(0, 9);
label1.alwaysShowSelection = true;
var label2:TextField = createCustomTextField(0, 50, 200, 20);
label2.text = "Drag to select some of this text.";
}
private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x; result.y = y;
result.width = width; result.height = height;
addChild(result);
return result;
}
}
}
对应swf文件
/Files/dreamcs/TextField_alwaysShowSelection.swf
待续
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html
浙公网安备 33010602011771号