![]() |
|
||||||||||
|
|||||
|
Регистрация: Jun 2004
Адрес: Екб
Сообщений: 63
|
Добрый день.
Уже открыл такую тему в общих вопросах, но ответа не нашлось. Думаю здесь она даже уместней. Столкнулся с следующей проблемой: Есть нефиксированное количество кнопок. Вешаю на них код циклом(все это происходит при получении данных из файла) : this.vars = new LoadVars();
this.vars.load("data.txt");
this.vars.onLoad = function() {
for (i=1; i<=this.num; i++) {
_root.txt4['anons_item'+i].anons_btn.onRelease = function(){
код
}
}
}
this.vars = new LoadVars();
this.vars.load("data.txt");
this.vars.onLoad = function() {
for (i=1; i<=this.num; i++) {
_root.txt4['anons_item'+i].anons_btn.onRelease = function(){
trace(i);
}
}
}
Помогите отцы ![]() |
|
|||||
|
Регистрация: Jun 2005
Адрес: spb
Сообщений: 84
|
помоему здесь проще с XML
function delaemMenu() {
var node_xml = menu_xml.firstChild;
var curr_node;
var curr_item;
var curr_menu = this.createEmptyMovieClip("mainmenu_mc", 0);
for (var i = 0; i<node_xml.childNodes.length; i++) {
curr_item = curr_menu.attachMovie("menuitem", "item"+i+"_mc", i);
curr_item._x = 0;
curr_item._y = i*curr_item._height;
curr_item.trackAsMenu = true;
curr_node = node_xml.childNodes[i];
curr_item.node = node_xml.childNodes[i];
// attributes to menuitem
curr_item.razdel = curr_node.attributes.razdel;
curr_item.onRelease = function() {
trace(this.razdel);
};
}
// end for
}
Последний раз редактировалось Der Grossen; 13.10.2005 в 13:01. |
|
|||||
|
Регистрация: Jun 2004
Адрес: Екб
Сообщений: 63
|
Спасибо, уже по другому решил.
|
|
|||||
|
ну блин никак, у тяж кнопка откуда знает чему i равно???
this.vars = new LoadVars(); this.vars.load("data.txt"); this.vars.onLoad = function() { for (i=1; i<=this.num; i++) { //вот здеся если написать так _root.txt4['anons_item'+i].anons_btn.i=i; _root.txt4['anons_item'+i].anons_btn.onRelease = function(){ //а здеся исправить trace(i); на trace(this.i); } } } |
|
|||||
|
Регистрация: Jun 2004
Адрес: Екб
Сообщений: 63
|
Так и решил
![]() Но все равно спасибо за ответ. |
|
|||||
|
Да... верно -
trace(this.i); такая маленькая разница а такой большой смысл Проверено.. так будет работать |
![]() |
![]() |
Часовой пояс GMT +4, время: 12:01. |
|
|
« Предыдущая тема | Следующая тема » |
|
|