
Код:
for (var i:int = 0; i < xml.news.item.length(); i++) {
//Creating the textfield object and naming it "myTextField"
var myTextField:TextField = new TextField();
//Here we add the new textfield instance to the stage with addchild()
page_mc.addChild(myTextField);
//textArray.push(myTextField);
//Here we define some properties for our text field, starting with giving it some text to contain.
//A width, x and y coordinates.
//myTextField.name = i;
myTextField.htmlText = XML(xml.news).item[i].zag;
myTextField.width = 250;
if (i == 0) {
myTextField.x = int(myTextField.width / 2 - myTextField.width + stage.stageWidth / 2) - 211;
myTextField.y = int(myTextField.height / 2 - myTextField.height + stage.stageHeight / 2) + 70;
}
if (i == 1) {
myTextField.x = int(myTextField.width / 2 - myTextField.width + stage.stageWidth / 2) + 174;
myTextField.y = int(myTextField.height / 2 - myTextField.height + stage.stageHeight / 2) + 70;
}
if (i == 2) { myTextField.x = int(myTextField.width / 2 - myTextField.width + stage.stageWidth / 2) - 205;
myTextField.y = int(myTextField.height / 2 - myTextField.height + stage.stageHeight / 2)+230;
}
if (i == 3) { myTextField.x = int(myTextField.width / 2 - myTextField.width + stage.stageWidth / 2) + 174;
myTextField.y = int(myTextField.height / 2 - myTextField.height + stage.stageHeight / 2) + 230;
}
//
//myTextField.alpha = 0;
//Here are some great properties to define, first one is to make sure the text is not selectable, then adding a border.
myTextField.selectable = false;
myTextField.border = false;
//This last property for our textfield is to make it autosize with the text, aligning to the left.
myTextField.autoSize = TextFieldAutoSize.LEFT;
//This is the section for our text styling, first we create a TextFormat instance naming it myFormat
var myFormat:TextFormat = new TextFormat();
//Giving the format a hex decimal color code
myFormat.color = 0x000000;
myFormat.font = "Myriad Pro";
//Adding some bigger text size
myFormat.size = 14;
//Last text style is to make it italic.
myFormat.bold = true;
//Now the most important thing for the textformat, we need to add it to the myTextField with setTextFormat.
//myTextField.setTextFormat(myFormat);
////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
Всё бы хорошо если б не строчка myTextField.setTextFormat(myFormat); - оно не отрабатывает.
P.S. как потом иметь доступ к myTextField за пределами for() ?!