A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Duplicate 1 MC at a time in a loop? (Flash 8)

  1. #1
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51

    Duplicate 1 MC at a time in a loop? (Flash 8)

    Hey, I got this working but it duplicates the number of MCs in the loop all in one click.

    I want it to duplicate the MC 1 at a time as the user clicks the button until the loop number limit is reached. Can anyone help me out here?


    on (release) {

    for(var i:Number = 1; i < 10; i++) {
    _root.cell.duplicateMovieClip("cell" + i, i, {_x:200, _y:200});

    }
    }



    Thanks in advance!

    Spit

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    take your code off of the button
    give the button an instance name
    place code on the main timeline
    PHP Code:
    var i:Number 0;

    btn.onRelease = function(){
    i++;
    _root.cell.duplicateMovieClip("cell" ii, {_x:200_y:200});
    }; 
    note: using your positioning code, all duplicates will appear at x:200, y:200

  3. #3
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    First off, program in a frame, not on a button. Give your button an instance name of myButton, and then write this into the main timeline frame:

    myButton.onRelease = function ()
    {
    //Do things
    }

    Anyways, declare a variable that counts:
    counter = 0;
    and then just keep adding to the counter var every time you click, and check if it's over a certain number (10 for example).

    Edit: Ha, well a_modified_dog beat me to it.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  4. #4
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51
    Thanks guys! I got it working just the way I wanted it to!

  5. #5
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51

    Feel like I'm loosing my mind...

    OK, I had this working where it would create 5 duplicate MCs of a MC called "cell". But as I was playing with other things in the movie, I came back to this and it started doing what it did before even after I removed all the new stuff I added.

    It only duplicates the first and then the next time you press the button it just repositions the first duplicate to a different spot. It was making 5.

    // Executes when the Duplicate button is released

    var i:Number = 0;

    _root.Duplicate.onRelease = function(){
    i++;
    if (cellCount < 5) {
    _root.cell.duplicateMovieClip("cell" + i, i, {_x: 100+random(400), _y: 100+random(400)});
    _global.cell_created = 1;
    _global.cellCount = cellCount + 1;

    }
    count.text = cellCount;


    }

  6. #6
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    I've never had too much experience with duplicateMovieClip, as I quickly switched to attachMovie, which seemed a lot more stable and cleaner, since you don't need to have movieclips on stage to duplicate.

    Edit:
    So, thinking I better make a point in this message, attachMovie in my experience works a lot better, but if you're using duplicateMovieClip the only problem I can see is if you're using the i variable in a for loop or something somewhere else where it gets overwritten...It looks like you're doing something like that.
    Last edited by Pazil; 06-06-2009 at 09:16 PM. Reason: Pressed Post button too early...
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

Tags for this Thread

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