dynamisches Textfeld mit Text füllen

intercorni

Erfahrenes Mitglied
Hallo,

ich erzeuge ein leeres dynamisches Textfeld:
PHP:
//textfeld erzeugen
var my_fmt:TextFormat = new TextFormat();
my_fmt.font = "Polo22K";
my_fmt.size = 80;
my_fmt.color = 0xFFFFFF;
my_fmt.align = "center";
this.createTextField("my_txt", this.getNextHighestDepth(), 40, 300, 700, 160);
my_txt.autoSize = "center";
my_txt.multiline = true;
my_txt.align = "center";
my_txt.wordWrap = true;
my_txt.border = false;
my_txt.embedFonts = true;
my_txt.text = "";
my_txt.setTextFormat(my_fmt);
my_txt._alpha = 100;
Und das versuche ich dann per function-Aufruf zu füllen, was jedoch nicht funktioniert:
PHP:
//textdefinition01
function textdefinition01() { 
	my_txt._alpha = "100"
	my_txt.text = "neuer Text";
	my_txt.setTextFormat(my_fmt);
	}
textdefinition01()
Warum geht das nicht bzw. was mache ich hier falsch?

Danke,

Cornel
 
Hallo,

das erste, was mir auffällt, ist, dass du der _alpha-Eigenschaft einen String zuordnen willst, was nicht funktionieren kann. Ausserdem musst du das textFormat-Objekt nicht zweimal dem Textfeld zuweisen. Dann rate ich dir, hier setNewTextFormat zu verwenden, da du dem gesamten Textfeld einen neuen Stil zuordnen willst und nicht etwa einer bestimmten Textstelle:

Code:
var my_fmt:TextFormat = new TextFormat();
with (my_fmt) {
   font = "Polo22K";
   size = 80;
   color = 0xFFFFFF;
   align = "center";
}

this.createTextField("my_txt", this.getNextHighestDepth(), 40, 300, 700, 160);
with (my_txt) {
   autoSize = "center";
   multiline = true;
   wordWrap = true;
   border = false;
   embedFonts = true;
   setNewTextFormat(my_fmt);
   _alpha = 100;
}

Die Funktion:
Code:
function textdefinition01() { 
    my_txt.text = "Hallo Welt!";
}
textdefinition01();

gruss

PS: Nicht getestet!
 
Zurück