Hello, help please!!! I'm being mad, I need to assign one image to each button I have in stage (12 in total) I've made some lops, in order to create the butons and to load the images from hd, but I get the same image in the buttons, so my loops aren't ok could you please have a look to my code? Thanks! _global.init = 0; loader._visible = 0; alpha_over = 100; alpha_out = 50; rows = 2; colunas = 6; numPics = 13; lv = new LoadVars(); lv.load("phps/listar_icones.txt"); lv.onload = function(sucesso) { if (sucesso) { arr = unescape(lv.vars); pics = arr.split("\n"); for (i=0; i<pics.length; i++) { pic = pics; trace(pic); pics.pop(); icones = "_root.icone"+pic+".loaderzinho"; icones.loadMovie("pics/"+pic, icones); btn_Array = new Array(); for (var y = 0; y<rows; y++) { for (var x = 0; x<colunas; x++) { i++; duplicateMovieClip(icone, "icone"+i, i); btn_Array = _root["icone"+i]; btn_Array._x = x*icone._width+35; btn_Array._y = y*icone._height+158; btn_Array._alpha = 50; btn_Array.loaderzinho.loadMovie("pics/"+pic+""); } } } } };
because this forum interprets [ i ] as encoding italic font it's difficult to see exactly what you're doing. but there are some potential problems with: icones = "_root.icone"+pic+".loaderzinho"; // icones is a string icones.loadMovie("pics/"+pic, icones); // this won't make sense unless you have flash convert your string into an object an even greater problem is your increment of your loop variable i in a nested x-y double loop. you surely don't want to do that. it's also, not clear what you're doing by using the pop() method of your pics() array. do you know that you're eliminating the last element of pics() before you use it?
Hi Kglad :-) Thanks for help! I've always have this problem when doing loops... I haven't yet completely untherstand when to loop or not to loop... Yes, I've removed that pics.pop() and it works. Howeaver, this isn't ok, because using the duplicateMovieClip, one image, the first one doesn't appear. Basically, I need to have in stage 12 images, each one a botton, so I can press and load a biguer one whith the description of what she is. Than I will have a forward button and a back button, thats why I have in the begining of code init = 0 On forward press I get another 12 images and so on. What do you sugest? I think this is better whith attachMovie, but I'm not getting this to work
hello again, I've simplyfied the code. Now, I get everyting traced, but still can't load the pics into the buttons... lv = new LoadVars(); lv.load("phps/listar_icones.txt"); lv.onload = function(sucesso) { if (sucesso) { arr = unescape(lv.vars); pics = arr.split("\n"); for (i=0; i!=pics.length; i++) { _root.createEmptyMovieClip("loader_btns", this.getNextHighestDepth()); _root.loader_btns.attachMovie("icones", "icones"+i, this.getNextHighestDepth(), {_x:x*["icones"+i]._width+35, _y:y*["icones"+i]._height+158}); trace(["icones"+i]); _root.loader_btns["icones"+i].loaderzinho.loadMovie("pics/"+pics+""); trace(pics); } } } can you please have a look? Thanks!
you're still using a [ i ] in your code and that still makes it difficult to read. use ivar or k or something other than i. that said, what's: _root.loader_btns["icones"+i].loaderzinho.loadMovie("pics/"+pics+""); i infer this should be: _root.loader_btns["icones"+i].loaderzinho.loadMovie("pics/"+pics[ivar]+""); but what's the point of the +"" that follows pics[ivar]? and i assume there's a movieclip with instance name loaderzinho in icones
ok, I've changed the i for k no, doesn't work... and yes, there is a loaderzinho inside icones. I'm really mad whith this :-( lv = new LoadVars(); lv.load("phps/listar_icones.txt"); lv.onload = function(sucesso) { if (sucesso) { arr = unescape(lv.vars); pics = arr.split("\n"); for (k=0; k!=pics.length; k++) { _root.createEmptyMovieClip("loader_btns", this.getNextHighestDepth()); _root.loader_btns.attachMovie("icones", "icones"+k, this.getNextHighestDepth(), {_x:x*["icones"+k]._width+35, _y:y*["icones"+k]._height+158}); trace(["icones"+k]); _root.loader_btns["icones"+k].loaderzinho.loadMovie("pics/"+pics[k]); trace(pics[k]); } } }
tracing this, I get this in output: icones0 pic_3.jpg icones1 pic_4.jpg icones2 pic_5.jpg icones3 pic_7.jpg icones4 pic_6.jpg icones5 pic_1.jpg icones6 pic_2.jpg icones7 Error opening URL "file:///Hugo/Library/Apache2/htdocs/Mobidecor/pics/"
is pics[0] supposed to be pic_3.jpg? and flash is not finding a pics directory (which should be a subdirectory of the directory where this flash file is stored). and just to make sure all your movieclips are defined run your code once with an extra trace statement (given below) and copy and paste the output: lv = new LoadVars(); lv.load("phps/listar_icones.txt"); lv.onload = function(sucesso) { if (sucesso) { arr = unescape(lv.vars); pics = arr.split("\n"); for (k=0; k!=pics.length; k++) { _root.createEmptyMovieClip("loader_btns", this.getNextHighestDepth()); _root.loader_btns.attachMovie("icones", "icones"+k, this.getNextHighestDepth(), {_x:x*["icones"+k]._width+35, _y:y*["icones"+k]._height+158}); trace(["icones"+k]); _root.loader_btns["icones"+k].loaderzinho.loadMovie("pics/"+pics[k]); trace(pics[k]); trace(_root.loader_btns["icones"+k].loaderzinho); } } }
Hello Kglad, I've made that trace and again, I've this well done, everything is as it should, but doesn't work. I have the directory pics in the correct place (htdocs/Mobidecor/pics/) , flash isn't recognizing the values, I don't know why. If I change the loadMovie to loadMovie(".../htdocs/Mobidecor/pics/pic_1.jpg"), I get pic 1 in place. What should I do? Many thanks! this is the new output: icones0 pic_3.jpg _level0.loader_btns.icones0.loaderzinho icones1 pic_4.jpg _level0.loader_btns.icones1.loaderzinho icones2 pic_5.jpg _level0.loader_btns.icones2.loaderzinho icones3 pic_7.jpg _level0.loader_btns.icones3.loaderzinho icones4 pic_6.jpg _level0.loader_btns.icones4.loaderzinho icones5 pic_1.jpg _level0.loader_btns.icones5.loaderzinho icones6 pic_2.jpg _level0.loader_btns.icones6.loaderzinho icones7 _level0.loader_btns.icones7.loaderzinho Error opening URL "file:///Hugo/Library/Apache2/htdocs/Mobidecor/pics/"
first, flash is finding all your pics except pics[7] is undefined. that's why there's no trace ofr pics[7] and your error message is truncated. 2nd, all your pictures (pics[0]...pics[6]) are being loaded correctly. they're just all at _x_y=0 because the following statement is problematic: _root.loader_btns.attachMovie("icones", "icones"+k, this.getNextHighestDepth(), {_x:x*["icones"+k]._width+35, _y:y*["icones"+k]._height+158}); change it to the following and see if you get what you want: _root.loader_btns.attachMovie("icones", "icones"+k, this.getNextHighestDepth(), {_x:k*35, _y:k*158});
Hello Kglad, No, that did not work. Howeaver I did this working as expected using the first code I've posted here, respecting your sugestions, removing tet pop() etc. He places the buttons on stage, divides them into 6 collumns and 2 row, and he is know loading the pic into their places. I've made just a litle change there arr = unescape(lv.vars); pics = arr.split("\n"); pics.sort(); Using this sort() everything works now. I've just one more question and I hope you can help me on this one too :-) those are buttons whith an image loaded into each. the images came from an load vars event, and are splited into single values, whitch on trace are correct. The question is: How do I make a global var for a onPress my var = this.button.image? I'm trying like this: btn_Array[k].onPress = function() { _global.icone = this.loaderzinho.pics[k]; trace(_global.icone); } but all I get is. icone=_level0.icone and I need icone = pic_3.jpg; (exemple) Can you please help? Thanks a lot!
if that code is on the same timeline as the rest of this code we've been discussing use: btn_Array[k].onPress = function() { _global.icone = pics[this.kvar]; trace(_global.icone); } where you edit your code that looks like: duplicateMovieClip(icone, "icone"+k, k); btn_Array[k] = _root["icone"+k]; to: duplicateMovieClip(icone, "icone"+k, k); btn_Array[k] = _root["icone"+k]; btn_Array[k].kvar=k;
Allright, it's working! Thank you so much Kglad, you're really a good friend :-)
Don't see what you're looking for? Try a search.
|