There are 5 buttons. Each button removes previously created textfields (previewTx) and creates a new textfield using an embeded font type.
Below is the code. Is there better way of achieveing this?
txX = 10
txY = 0;
txW = 530;
txH = 20;
var csFormat0:TextFormat = new TextFormat();
csFormat0.font = "Times";
csFormat0.size = 16;
csFormat0.color = 0x000000;
csFormat0.align = "center";
function fontt0() {
previewTx.removeTextField();
this.createTextField("previewTx", 5000, txX, txY, txW, txH);
previewTx.setNewTextFormat(csFormat0);
fontInfo();
}
var csFormat1:TextFormat = new TextFormat();
csFormat1.font = "arial";
csFormat1.size = 16;
csFormat1.color = 0x000000;
csFormat1.align = "center";
function fontt1() {
previewTx.removeTextField();
this.createTextField("previewTx", 5000, txX, txY, txW, txH);
previewTx.setNewTextFormat(csFormat1);
fontInfo();
}
function fontInfo() {
previewTx.embedFonts = true;
previewTx.selectable = true;
previewTx.text = "ABCDE";
previewTx.border = true;
previewTx.type = "input";
previewTx.multiline = true;
previewTx.wordWrap = true;
}
font0.onRelease = function () {
fontt0();
}
font1.onRelease = function () {
fontt1();
}
you could use one font function:
function fontF(n:Number):Void{
previewTx.removeTextField();
this.createTextField("previewTx", 5000, txX, txY, txW, txH);
previewTx.setNewTextFormat(this["csFormat"+n]);
fontInfo();
}
for(var i:Number=0;i<fontNum:i++){
this["font"+i].ivar=i;
this["font+i].onRelease=function(){
fontF(this.ivar);
}
}
// and if the only difference among your textformats is the font, you could create one textformat and change its font property in fontF and that would save a lot of repetitive code.