flash actionscript:
Hello, I'm trying to make 25 buttons to use in a contact list using an array, and assigning instance name to each equal to the item of the array exemple my_array = new Array("A", "B", "c"); for(k=0; k<my_array.length; k++){ _root.createEmptyMovieClip("my_array[k]", 0+k); } this traces A, B, C thats ok, but now trying tho define the _x and _y doesn't work, in spite of the trace comand show the right numbers... Any help please? This is the code: Note that It would output name of button is "A", but it doesn't, I think this is the problem btns_lista = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); for (btn=0; btn<btns_lista.length; btn++) { _root.createEmptyMovieClip("btns_lista[btn]", 0+[btn]); trace("name of button is "+btn); round_corners("_root.btns_lista[btn]", 15, 15, 0.5, 0xFF7223, 100, 0xFFFFFF, 0, 0); _root["btns_lista[btn]"]._x = 620; trace("x position of button is "+_root["btns_lista[btn]"]._x); _root["btns_lista[btn]"]._y = 83.6+btn*20; trace("y position of button is "+_root["btns_lista[btn]"]._y); } And here the output name of button is 0 x position of button is 620 y position of button is 83.6 name of button is 1 x position of button is 620 y position of button is 103.6 name of button is 2 x position of button is 620 y position of button is 123.6 name of button is 3 x position of button is 620 y position of button is 143.6
When you reference the buttons using the _root[] notation, don't put quotes around the array name. Change _root['btns_lista[btn]'] to _root[btns_lista[btn]]
hello, thanks for help! no, thats why i think this strange, i get undifined name of button is A x position of button is undefined y position of button is undefined name of button is B x position of button is undefined y position of button is undefined name of button is C x position of button is undefined y position of button is undefined
< your code is all wrong > :-) - It was not so wrong... :-( I just added this "" in the wrong place
your code is all wrong .. you seem to have no idea what quoted strings and [] do at all .. please change my_array = new Array("A", "B", "c"); for(k=0; k<my_array.length; k++){ _root.createEmptyMovieClip("my_array[k]", 0+k); } to this my_array = new Array("A", "B", "c"); for (k=0; k<my_array.length; k++) { _root.createEmptyMovieClip(my_array[k], k); } and change for (btn=0; btn<btns_lista.length; btn++) { _root.createEmptyMovieClip("btns_lista[btn]", 0+[btn]); trace("name of button is "+btn); round_corners("_root.btns_lista[btn]", 15, 15, 0.5, 0xFF7223, 100, 0xFFFFFF, 0, 0); _root["btns_lista[btn]"]._x = 620; trace("x position of button is "+_root["btns_lista[btn]"]._x); _root["btns_lista[btn]"]._y = 83.6+btn*20; trace("y position of button is "+_root["btns_lista[btn]"]._y); } to this for (var btn = 0; btn < btns_lista.length; btn++) { _root.createEmptyMovieClip(btns_lista[btn], btn); trace("name of button is "+_root[btns_lista[btn]]._name); round_corners(_root[btns_lista[btn]], 15, 15, 0.5, 0xFF7223, 100, 0xFFFFFF, 0, 0); _root[btns_lista[btn]]._x = 620; trace("x position of button is "+_root[btns_lista[btn]]._x); _root[btns_lista[btn]]._y = 83.6+btn*20; trace("y position of button is "+_root[btns_lista[btn]]._y); } or even better, to this for (var btn = 0; btn < btns_lista.length; btn++) { var button = _root.createEmptyMovieClip(btns_lista[btn], btn); trace("name of button is "+button._name); round_corners(button, 15, 15, 0.5, 0xFF7223, 100, 0xFFFFFF, 0, 0); button._x = 620; trace("x position of button is "+button._x); button._y = 83.6+btn*20; trace("y position of button is "+button._y); } -- All the best, Jeckyl
Don't see what you're looking for? Try a search.
|