A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: duplicateMovieClip AS2

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    20

    duplicateMovieClip AS2

    Hi, and sorry for being stupid.
    I am trying to get some actions on a duplicated MovieClip
    Now what I got is something like this:
    Actionscript Code:
    // I have some loop wrapped around this so the 'i' changes.
    duplicateMovieClip("target", "new"+i, 100+i);
    // I use 'i' because i need a few of those...

    for(i=0;i<somenumber;i++){
    _root["new"+i].onEnterFrame = function(){
    //actions
    }
    }

    And it won't work. Logically it just makes MCs "new1" "new2" "new3" and so on.And then it checks for those.
    If i put a MC named "new3" on stage, it works. I guess i'm just stupid and doing the duplication wrong or something.
    Any help? Thanks.

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    This may be nothing but try changing the var name of i in the second loop to something else, like "j". HTH.
    Wile E. Coyote - "Clear as mud?"

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    20
    Oh no.. here it's like this, to illustrate. In the code they have different names.(though it really doesn't matters if they are in different 'for' loops)
    I did some checking using 'trace' to see the names of the duplicates and they sees to be fine...But it doesn't work.
    If i put them manually on the stage and name them something like 'new1' 'new2' and so on then it works..

  4. #4
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    When using the duplicate function what code is being used for x and y placement. Chances are it is working, it's just putting them all on top of each other.
    Wile E. Coyote - "Clear as mud?"

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    20
    Well, it's not just the X, Y placement,even if i do something like 'trace' under that it won't work.(I mean the second part of my code)
    But i'm using:
    duplicateMovieClip("target", "new"+i, 100+i);
    _root["new"+i]._x = somex;
    _root["new"+i]._y = somey;

    I don't know what can go wrong here...

  6. #6
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Try uploading your file and I'll have a look at it.
    Wile E. Coyote - "Clear as mud?"

  7. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    20
    This is not the full file (because it's too big)
    so i just made an illustration.
    You duplicate by clicking and I tried rollover here..
    Attached Files Attached Files

  8. #8
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Do this and it will work, in the main timeline the actions should be as follows.
    PHP Code:
    var 1;

    onMouseDown = function () {
        if (
    i<6) {
            
    duplicateMovieClip("rect""new"+i100+i);
            
    this["new"+i]._x this._xmouse;
            
    this["new"+i]._y this._ymouse;
            
    this["new"+i]._name "new" i;
            
    i++;
        }

    Then add this code to the "rect" library object,
    PHP Code:
    this.onRollOver = function() {
        
    trace(this._name);

    Wile E. Coyote - "Clear as mud?"

  9. #9
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Or if you want the code on the main timeline, try something like this, it worked for me.
    PHP Code:
    for(var 010i++) {
        
    duplicateMovieClip("target""mc"+ithis.getNextHighestDepth());
        
    this["mc"+i]._x Math.random() * Stage.width;
        
    this["mc"+i]._y Math.random() * Stage.height;
        
        for(var 
    j=010j++) {
            
    this["mc"+j].onPress = function() {
                
    trace(this._name);
            }
        }

    HTH.
    Wile E. Coyote - "Clear as mud?"

  10. #10
    Junior Member
    Join Date
    Sep 2010
    Posts
    20
    Oh finally, a solution. I hope i can fit this to work with my code.

    Thanks a lot!
    EDIT: the first idea worked for me and seems comfortable for my code, so i'm going to use that.
    thanks!

  11. #11
    Junior Member
    Join Date
    Apr 2020
    Posts
    1
    Hola chicos necesito hacer un practico es basico pero no recuerdo como era, tengo que hacer 1 circulo como movieclip, y con attachMovie o DuplicateMovieClip, con for(); _x y _width, el 3 circulo tiene que ser más angosto que los otros 3. yo use este codigo pero solo aparecen 2 circulos y uno se deforma. solo es duplicar cuatro circulos no se usa boton ni mouse

    duplicateMovieClip(circulo_mc, "circulo_nuevo", this.getNextHighestDepth());
    circulo_nuevo._x = 150;
    circulo_nuevo._width = 50;

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