A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: duplicateMovieClip

  1. #1
    Member
    Join Date
    Nov 2003
    Location
    Netherlands
    Posts
    91

    duplicateMovieClip

    According to the Actionscript Dictionary, I should use the following code for duplicating movieclips:

    (action assigned to a button)
    on (release) {
    amount = 10;
    while (amount>0) {
    duplicateMovieClip (_root.flower, "mc"+i, i);
    setProperty ("mc"+i, _x, random(275));
    setProperty ("mc"+i, _y, random(275));
    setProperty ("mc"+i, _alpha, random(275));
    setProperty ("mc"+i, _xscale, random(50));
    setProperty ("mc"+i, _yscale, random(50));
    i++;
    amount--;
    }
    }

    However... this doesn't work.

    Now if I change the target in the setProperty lines from "mc"+i to "_root.flower", then it does work.
    Would make more sense if the setProperty functions were called before duplicating the movie.

    Explanations are most welcome.
    Ha, ha! He is one of the Legion Lost;
    He was never meant to win;

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    is the button inside a movie clip? it should work otherwise.

    When you use duplicateMovieClip the new clips are created in the same timeline as the original clip, so the here the new clips would be created on the main timeline _root, because that is where flower is. However if that button is inside a movie clip the new clips are made, but the setProperty lines are looking inside the current timeline to find the new clips (which aren't there),

    try this instead,

    code:

    on (release) {
    amount = 10;
    while (amount>0) {
    duplicateMovieClip (_root.flower, "mc"+i, i);
    _root["mc" + i]._x = random(275);
    _root["mc" + i]._y = random(275);
    _root["mc" + i]._alpha = random(100);
    _root["mc" + i]._xscale = random(50);
    _root["mc" + i]._yscale = random(50);
    i++;
    amount--;
    }
    }


  3. #3
    Member
    Join Date
    Nov 2003
    Location
    Netherlands
    Posts
    91
    Thank you. That did the trick.

    My button was not inside a movieclip.
    I just fixed my own code as well.

    setProperty ("mc"+i, _x, random(275)); should have been setProperty ("_root.mc"+i, _x, random(275));

    The duplicateMovieClip worked just fine, but because Flash failed to set the properties of the mc+i clips, they all overlapped eachother and I never got to see any results.

    I should have known better to just copy/paste text from a helpfile.
    Thanks again.
    Ha, ha! He is one of the Legion Lost;
    He was never meant to win;

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