243 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Located in Europe
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

8302 posts Community Moderator
  • Has referred 10+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Attended one of our Meetups around the world
+9 more
MSFX 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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Located in Europe
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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
+5 more
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
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Located in Europe
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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by