A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: duplicateMovieClip

  1. #1
    AFX == P. Forsberg
    Join Date
    Nov 2001
    Posts
    439

    duplicateMovieClip

    Hello. I am using duplicateMovieClip to create a wallpaper of sorts. I am trying to get the mc to tile the majority of the screen. What is the most efficient way of writing the positioning for this? You can see below that I am switching the x value once i is greater than 8. I am trying to avoid nesting a lot of if statements.

    Does this make sense?



    Code:
    for (var i = 0; i<16; ++i) {
    	// create the new clip
    	var mc = myClip.duplicateMovieClip("myClip"+i, i);
    	// position the clip
    	if (i<8) {
    		mc._x = 40;
    		mc._y = 40+i*40;
    	} else {
    		mc._x = 80;
    		mc._y = 40+(i-8)*40;
    	}
    	// now add an onPress event for the clip
    	mc.onRelease = function() {
    		trace(this._name);
    		trace(this._y);
    	};
    }
    Thanks in advance,
    1M.

  2. #2
    AFX == P. Forsberg
    Join Date
    Nov 2001
    Posts
    439

    mod

    I guess my question boils down to mod (modulus) syntax in AS.

    Any takers?

    Thanks,
    1M.

  3. #3
    Flash Kit Moderator Genesis F5's Avatar
    Join Date
    Jan 2002
    Location
    Unallocated memory
    Posts
    1,845
    What would you need to use modulus for? That just returns a remainder.

    If you're trying to tile something, use this method.

    Code:
    onClipEvent(mouseDown)
    {
    //############# USER INPUT ###############
    swidth=500;  //INPUT STAGE WIDTH
    sheight=400; //INPUT STAGE HEIGHT
    clipname="myClip";
    //########### END USER INPUT #############
    tilewidth=eval("_root."+clipname)._width;
    tileheight=eval("_root."+clipname)._height;
    
    for (a=0;a<=sheight;a+=tileheight)
    {
    for (b=0;b<=swidth;b+=tilewidth)
    {
    eval("_root."+clipname).duplicateMovieClip(clipname+i, i);
    eval("_root."+clipname+i)._x=b;
    eval("_root."+clipname+i)._y=a;
    i++
    }}}
    I wrote the code so all you need to do is edit the user options.

    I hope this helps.

    -genesis f5 (mx)

  4. #4
    AFX == P. Forsberg
    Join Date
    Nov 2001
    Posts
    439

    modulus

    I'm looking to tile in rows of 8. if (i%8 == 0) { would be a good way to say start a new row/ column. I will try your code out. Being stubborn as an ox, I am also trying to figure the module way .

    Thanks,
    I'll post my findings,
    1M.

  5. #5
    Flash Kit Moderator Genesis F5's Avatar
    Join Date
    Jan 2002
    Location
    Unallocated memory
    Posts
    1,845
    Then you need to divide your width/height by 8 and then use that in your for loop.

    Change the code to this:


    Code:
    onClipEvent(mouseDown)
    {
    //############# USER INPUT ###############
    swidth=500;  //INPUT STAGE WIDTH
    sheight=400; //INPUT STAGE HEIGHT
    clipname="myClip";
    tiles=8;
    //########### END USER INPUT #############
    tilewidth=eval("_root."+clipname)._width;
    tileheight=eval("_root."+clipname)._height;
    
    for (a=0;a<sheight;a+=sheight/tiles)
    {
    for (b=0;b<swidth;b+=swidth/tiles)
    {
    eval("_root."+clipname).duplicateMovieClip(clipname+i, i);
    eval("_root."+clipname+i)._x=b;
    eval("_root."+clipname+i)._y=a;
    i++
    }}}
    I hope this helps

    -genesis f5 (mx)

  6. #6
    AFX == P. Forsberg
    Join Date
    Nov 2001
    Posts
    439

    6 of 1, half a dozen of the other

    Genesis f5, thanks for your code. It did work. I was also able to get the mod working:

    code:

    rowCount = 63;
    col = 1;
    row = 1;
    for (var i = 0; i<=rowCount; i++) {
    var mc = myClip.duplicateMovieClip("myClip"+i, i);
    col++;
    if (i%8 == 0) {
    row++;
    col = 1;
    }
    mc._x = col*40;
    mc._y = row*40;
    }



    This code makes 8 rows of 8.

    Thought I'd post it for others.

    Thanks GF5,
    1M.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center