Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Other Scripting Languages (http://www.programmingforums.org/forum39.html)
-   -   actionscript 2.0 for-loop logic problem (http://www.programmingforums.org/showthread.php?t=13962)

Simongcc Sep 14th, 2007 3:19 AM

actionscript 2.0 for-loop logic problem
 
2 Attachment(s)
Dear All,

I am using Flash 8 and actionscript 2.0 to load a photoWall into moviescript.
While the script runs smoothly if I separate the inside i-loop into 4 blocks.
Or some of the images will be missed. Did I missing something in logic?

Thanks in advance.
Simon :confused:


:

  1. for (j = 0; j <= 3; j++) {
  2.         for (i = 0; i <= 4; i++) {
  3.                 trace(i);
  4.                 mainImgURL = generalDir+ "apart"+ i + j + ".jpg";
  5.                 photoWallImg = photoWallMC.attachMovie("xternalImageMC", "xternalImgMC_"+i+j, i+j);
  6.                 bigImgHolderMCL.loadClip(mainImgURL, photoWallImg);
  7.                 photoWallImg._y = 85 * j;                               
  8.                 photoWallImg._x = i * SPACING;
  9.                 trace("photoWallImg._y "+ photoWallImg._y);               
  10.                 trace("photoWallImg._x "+ photoWallImg._x);
  11.                 trace(mainImgURL);
  12.                 trace(photoWallImg);
  13.  
  14.         }
  15.  
  16. }
  17.  
  18.  
  19. /* //divided into four separate loops
  20. for (i = 0; i <= 4; i++) {
  21.                 mainImgURL = generalDir+ "apart"+ i + "0" + ".jpg";
  22.                 photoWallImg = photoWallMC.attachMovie("xternalImageMC", "xternalImgMC_"+i+"0", i+"0");
  23.                 bigImgHolderMCL.loadClip(mainImgURL, photoWallImg.loadPhotoMC);
  24.                 photoWallImg._x = i * SPACING;
  25. }
  26.  
  27. for (j = 0; j <= 4; j++) {
  28.                 mainImgURL = generalDir+ "apart"+ j + "1" + ".jpg";
  29.                 photoWallImg = photoWallMC.attachMovie("xternalImageMC", "xternalImgMC_"+j+"1", j+"1");
  30.                 bigImgHolderMCL.loadClip(mainImgURL, photoWallImg.loadPhotoMC);
  31.                 photoWallImg._y = 85;
  32.                 photoWallImg._x = j * SPACING;
  33. }
  34.  
  35. for (k = 0; k <= 4; k++) {
  36.                 mainImgURL = generalDir+ "apart"+ k + "2" + ".jpg";
  37.                 photoWallImg = photoWallMC.attachMovie("xternalImageMC", "xternalImgMC_"+k+"2", k+"2");
  38.                 bigImgHolderMCL.loadClip(mainImgURL, photoWallImg.loadPhotoMC);
  39.                 photoWallImg._y = 170;
  40.                 photoWallImg._x = k * SPACING;
  41. }
  42.  
  43. for (l = 0; l <= 4; l++) {
  44.                 mainImgURL = generalDir+ "apart"+ l + "3" + ".jpg";
  45.                 photoWallImg = photoWallMC.attachMovie("xternalImageMC", "xternalImgMC_"+l+"3", l+"3");
  46.                 bigImgHolderMCL.loadClip(mainImgURL, photoWallImg.loadPhotoMC);
  47.                 photoWallImg._y = 255;
  48.                 photoWallImg._x = l * SPACING;
  49. }
  50. */


dr.p Sep 14th, 2007 4:06 AM

I can't see what's wrong with the code at this point. It looks good.

You should put your code in code tags, by the way.

Simongcc Sep 14th, 2007 4:18 AM

thanks a lot, have got it fixed immediately.

Simongcc Sep 14th, 2007 7:46 AM

Problem resolved
 
Hihi!

I have resolved the problem:
There were 2 problems:
1. Since there is depth consideration in flash, the depth variable have problem. Some photos will be overlapped.
2. I have swapped the thought of column and row so that the image is missed if I combine the code together.

Hope this can set an opp. example.

Thanks!
Simon


:

  1. for (j = 0, k=0; j < 4; j++) {
  2.         for (i = 0; i < 5; i++, k++) {
  3.                 mainImgURL = generalDir+ "apart"+ j + i + ".jpg";
  4.                 photoWallImg = photoWallMC.attachMovie("xternalImageMC", "xternalImgMC_"+j+i, k);
  5.                 bigImgHolderMCL.loadClip(mainImgURL, photoWallImg);
  6.                 photoWallImg._x = 85 * i;               
  7.                 photoWallImg._y = 85 * j;               
  8.         }
  9. }


dr.p Sep 14th, 2007 6:11 PM

Thanks for posting your solution, Simon, and I'm glad you got it fixed. :)

Simongcc Sep 17th, 2007 6:51 AM

Summary of problems for all reference
 
Thanks, you are so nice!

Summary of image not load problem for reference:

1. movieclip name (the name inside script mismatch with the name of Mclip)
2. image path is not correct
3. depth checking(the result is weird if depth have problem)

whenever doing a complex scripts, return and make a simple script
as a testing probe. Hope this can save you from hours of frustration.

Cheers


All times are GMT -5. The time now is 9:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC