PDA

View Full Version : [fmx] FOR Loops and Function Question



jupiter
November 24th, 2004, 11:24 AM
HI, why this code dosenīt work at the same time in the timeline, and why only envent put inside the attacHMovies or duplicated Movies work, if i put them in the forr loops they donīt work.

Thanks people




img01 = new Array();
img01 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"];
for (i=1; i<=img01.length; i++) {
newclip = _root.content1.attachMovie("holder", "newclip"+i, i);
newclip._x = 0+x;
newclip._y = 0;
x += 109;
//trace(i);
}
img02 = new Array();
img02 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"];
for (j=10; j<=19; j++) {
newclip2 = _root.content2.attachMovie("holder", "newclip2"+j, j);
newclip2._x = 0+x;
newclip2._y = 100;
x += 109;
trace("j "+j);
trace(newclip2._y);
}

icio
November 24th, 2004, 11:31 AM
img01 = new Array();
img01 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"];
for (i=1; i<=img01.length; i++) {
_root.content1.attachMovie("holder", "newclip"+i, i);
_root.content1["newclip"+i]._x = x;
_root.content1["newclip"+i]._y = 0;
x += 109;
//trace(i);
}
img02 = new Array();
img02 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"];
for (j=10; j<=19; j++) {
_root.content2.attachMovie("holder", "newclip2"+j, j);
_root.content2["newclip2"+j]._x = 0+x;
_root.content2["newclip2"+j]._y = 100;
x += 109;
trace("j "+j);
trace(_root.content2["newclip2"+j]._y);
}

and also make sure that you have set the linkage for these movieclips. if you're unsure how to do this, select the movieclip you want to in the library, and then right-click and select linkage, check 'export for actionscipt' and give it the appropriate name.

hope this helps :thumb:

jupiter
November 24th, 2004, 11:56 AM
hi, Did you tried this code, the problem is that the dupes exists but they are all in the same place

icio
November 24th, 2004, 12:40 PM
hm..


x = 0;
//
img01 = new Array();
img01 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"];
for (i=0; i<img01.length; i++) {
_root.content1.attachMovie("holder", "newclip"+i, i);
_root.content1["newclip"+i]._x = x;
_root.content1["newclip"+i]._y = 0;
x += 109;
//trace(i);
}
//
x = 0;
//
img02 = new Array();
img02 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"];
for (j=0; j<img02.length; j++) {
_root.content2.attachMovie("holder", "newclip2"+j, j+img01.length);
_root.content2["newclip2"+j]._x = x;
_root.content2["newclip2"+j]._y = 100;
x += 109;
trace("j "+j);
trace(_root.content2["newclip2"+j]._y);
}

hope this helps :thumb:, but if it doesnt can you upload your fla?

icio
November 24th, 2004, 12:41 PM
or instead of specifying the depth, try puting:

_root.content1.getNextHighestDepth();
//and
_root.content2.getNextHighestDepth();

hope you resolve it :)

lostinbeta
November 24th, 2004, 02:35 PM
The reason there was a problem was because 'x' was overwriting itself.

Using cyberathletes method you are clearing x and starting over from scratch again. Which works, but I would recommend using 2 seperate variables (x1 and x2 maybe?). I'm not really sure if theres any real efficiency difference, just the way my mind works. Either method works though.

Also... img01 = new Array();
img01 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"];
img02 = new Array();
img02 = ["001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg"]; Those lines contradict eachother. [] is shorthand for new Array() so you don't need img01 = new Array() or img02 = new Array().

Basically...img01 = ["001.jpg", "002.jpg"];Is the same as saying...
img01 = new Array();
img01[0] = "img01.jpg";
img01[1] = "img02.jpg";or...img01 = new Array("001.jpg", "002.jpg");

And lastly..

@cyberathlete: I believe getNextHighestDepth() is a FMX 2k4 thing, FMX doesn't have this ability. (The title says "[fmx]" which is why I brought this up).

jupiter
November 25th, 2004, 05:17 AM
Hi to all, I tried all of your sugestions but nothing seems to work, Iīm a bit lost here. I will post the the fla for someone discover the problem.

thsnks to all

blah-de-blah
November 25th, 2004, 06:03 AM
What seems to be wrong? The 'Holders' seem to be duplicating properly..?

stringy
November 25th, 2004, 05:28 PM
Hi to all, I tried all of your sugestions but nothing seems to work, Iīm a bit lost here. I will post the the fla for someone discover the problem.

thsnks to all
you don`t need to specify the _y values as you have manually placed clips on the stage.

jupiter
November 26th, 2004, 05:56 AM
thanks

stringy
November 26th, 2004, 06:03 PM
thanks
welcome