![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
![]() |
|
|||||
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);
////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
P.S. как потом иметь доступ к myTextField за пределами for() ?! |
|
|||||
|
Цитата:
__________________
http://www.chessmax.ru |
|
|||||
|
как это сделать?
Добавлено через 2 часа 22 минуты помогите пожалуйста Добавлено через 2 часа 30 минут как писать: ? Последний раз редактировалось ader; 27.03.2012 в 01:20. |
|
|||||
|
Как-то так:
private var textArray: Array = []; //... 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); textArray.push(myTextField); ////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } //.... textArray[0].x = 500;
__________________
http://www.chessmax.ru |
|
|||||
|
Мне очень режут глаза блоки if (i == n)
И что, никак не обойтись без ручной установки координат? всё равно криво получается. убрал условия, да и в принципе, код еще почистить не мешало бы. import flash.geom.Point; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; var textArray:Array = []; var textPositions:Array = /* of Point */ [ new Point(-211, 70), new Point(174, 70), new Point(-205, 230), new Point(174, 230) ]; var quantity:int = 4; // xml.news.item.length() var text:String = "Some text "; // XML(xml.news).item[i].zag var page_mc:Sprite = new Sprite(); addChild(page_mc); var myFormat:TextFormat = new TextFormat(); myFormat.color = 0x000000; myFormat.font = "Myriad Pro"; myFormat.size = 14; myFormat.bold = true; for (var i:int=0; i<quantity; i++) { var myTextField:TextField = new TextField(); myTextField.htmlText = text + i; myTextField.width = 250; // height == ? myTextField.height = 100; myTextField.selectable = false; myTextField.border = false; myTextField.autoSize = TextFieldAutoSize.LEFT; myTextField.x = (myTextField.width + stage.stageWidth) /2 - myTextField.width + textPositions[i].x; myTextField.y = (myTextField.height + stage.stageHeight) /2 - myTextField.height + textPositions[i].y; myTextField.setTextFormat(myFormat); page_mc.addChild(myTextField); textArray.push(myTextField); }
__________________
adobe AS3 manual Последний раз редактировалось strangedk; 27.03.2012 в 11:13. |
|
|||||
|
Спасибо!!! . Подскажите пожалуйста как иметь доступ к mytextfield за пределами for() ?
команда textArray[0].x = 500; ругается на меня ![]() Добавлено через 4 минуты всё работает - спасибо! нужно делать арей в privat var иначе нет доступа за пределами for(); |
|
|||||
|
Цитата:
думаю нужно было сразу присылать целый класс, тогда бы и порешали как нужно
__________________
adobe AS3 manual |
|
|||||
|
Столкнулся с проблемой!
По неведомой причине myTextFiled не ембедидтся в page_mc Я так понял проблема кроется в Но как по синтаксису правильно пушнуть myTextField так, чтобы он находился в page_mc я незнаю. Помогите плиз! У меня прокрутка экрана стоит на page_mc - текст не прокручивается ![]() |
![]() |
![]() |
Часовой пояс GMT +4, время: 21:38. |
|
|
« Предыдущая тема | Следующая тема » |
|
|