243 posts
  • Europe
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
creativestuff says

I just wrote a little AS2 script that must fill up the Stage with a pattern.

here is the script:


stop();
Stage.align = "TL";
Stage.scaleMode = "noScale";
Stage.addListener(this);

onRs = function(){
    sW = Stage.width;
    sH = Stage.height;

    pW = pattern._width;
    pH = pattern._height;

    rH = 1+Math.round(sH/pH);
    rW = 1+Math.round(sW/pW);

    //trace(rH+" "+rW);

    for (i=1; i<=rH; i++)
     for (j=1; j<=rW; j++){
         duplicated = pattern.duplicateMovieClip("pattern"+i+j,i+j);
         duplicated.id = i+"-"+j;
         duplicated._x = pattern._x + (j-1)*pW;
         duplicated._y = pattern._y + (i-1)*pH;
      }
}
onRs();

the MC “pattern” and the AS are both on the _root the MC instance name is set and the x,y are 0.

now.. the strange thing is that only the last row is filled up , the rest of rows contain only first duplicated item…

can download the source: http://www.creativestuff.eu/strange.fla

check it out: http://www.creativestuff.eu/strange.swf

8221 posts Community Moderator
  • Attended a Community Meetup
  • Community Moderator
  • Has been a member for 6-7 years
  • United Kingdom
  • Contributed a Tutorial to a Tuts+ Site
  • Won a Competition
  • Contributed a Blog Post
  • Beta Tester
  • Bought between 50 and 99 items
+4 more
MSFX Volunteer moderator says

try tracing out to make sure all your loops are working…

I think with for loops when they are more than one line require the braces…?

243 posts
  • Europe
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
creativestuff says

traced out … doing all steps … and don’t necessary the { at the first loop because it is followed by only 1 instruction

2309 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 10 and 49 users
  • Repeatedly helped protect Envato Market against copyright violations
  • Sold between 100 and 1 000 dollars
  • United States
theflyingtinman says

Your problem is using i+j for the depths of the duplicate movieclips. This generates repeating values, replacing, for example, the movie clip at i=2 j=3 (depth 5) with the one at i=3 ,j=2 (depth 5). Eventually all but the last row will be replaced.

Use getNextHighestDepth() ( or j * rH + i ) and it will work.

162 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 100 and 1 000 dollars
  • Ukraine
FLEXIncubator says

Did you notice that if you unlink your trace line in the code above it will produce NaN value? Maybe this is the problem, because you feed for loops with not numbers.

243 posts
  • Europe
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
creativestuff says
Your problem is using i+j for the depths of the duplicate movieclips. This generates repeating values, replacing, for example, the movie clip at i=2 j=3 (depth 5) with the one at i=3 ,j=2 (depth 5). Eventually all but the last row will be replaced. Use getNextHighestDepth() ( or j * rH + i ) and it will work.

thank you so much :P

by
by
by
by
by
by