通过下拉框选择字体,再按照字体显示文本输入框中的文字。
下拉框的实例名为: my_cbo , 输入框的实例名为: tt .主场景中输入下面的代码即可。
代码如下:
//TextInput 组件
tt.text = "abcdefg";
userFonts = TextField.getFontList();
userFonts.sort();
for (i = 0; i < userFonts.length; i++) {
my_cbo.addItem({data:userFonts[i], label:userFonts[i]});
}
_root.createTextField("userText", 5, 10, 20, 220, 40);
//以下段落是对下拉框的响应
var cbListener:Object = new Object();
cbListener.change = function(evt_obj:Object) {
userfonts = evt_obj.target.selectedItem.label;
trace("Currently selected item is: " + userfonts);
_root["userText"].text = tt.text;
_root["userText"].border = true;
_root["userText"].background = true;
_root["userText"].backgroundColor = 0xffff00;
displayStyle = new TextFormat(userfonts, 18);
displayStyle.align = "left";
trace(userfonts);
_root["userText"].setTextFormat(0, 50, displayStyle);
tt.fontFamily = displayStyle;
};
my_cbo.addEventListener("change", cbListener);
//以下段落是对输入框的响应
var ttListener:Object = new Object();
ttListener.change = function() {
_root["userText"].text = tt.text;
_root["userText"].border = true;
_root["userText"].background = true;
_root["userText"].backgroundColor = 0xffff00;
displayStyle = new TextFormat(userfonts, 18);
displayStyle.align = "left";
trace(userfonts);
_root["userText"].setTextFormat(0, 50, displayStyle);
};
tt.addEventListener("change", ttListener);