duplicateMovieClip

Ou la la… I come back from vacation, and that’s what I see… Bread on the board, du pain sur la planche as we say…\r\rpom 0]

Hi once again!

That’s exactly what I want. But I don’t know where to put the code. I guess on the object (the circle) I want to duplicate. But is it onClipEvent (load), onClipEvent (enterFrame)? And do I have to put the settings, the function and the method there?

THX

Hartwig

assuming that myCircle is in _root, it can all go in frame 1. make sure to define the function before you call it, and don’t run the code more than once.

Hi!

Nothing tweens in my movie. Do you have a .fla which works. Could you send to [email protected].

THANKS THANKS THANKS THANKS THANKS

Hartwig

here’s some code you can drop into frame 1 of an empty fla.

there’s a few modifications, a method for drawing circles has been added, and makeDemMovies() has been amended to remove the added movie after the duplication, and the duped layer is j+1 to avoid overwriting “myCircle”.

the circles aren’t really that great a shape, oh well … ; )

  
_root.settings = [
   {_x:300,_y:300,tweenSpd:5,tweenMax:150},
   {_x:200,_y:200,tweenSpd:10,tweenMax:200}
];

MovieClip.prototype.makeCircle= function(r){
   var c = this.createEmptyMovieClip("myCircle",0);
   with (c){
      lineStyle(0);
      moveTo(0,-r);
      curveTo(r,-r,r,0);
      curveTo(r,r,0,r);
      curveTo(-r,r,-r,0);
      curveTo(-r,-r,0,-r);
   }
}

function makeDemMovies() {
   _root.makeCircle(50);
   var j,mc;
   for(j in _root.settings){
      mc = _root.myCircle.duplicateMovieClip("dupedCircle"+j,j+1,_root.settings[j]);
      mc.onEnterFrame = mc.tween;
   }
   _root.myCircle.removeMovieClip();
}

MovieClip.prototype.tween = function(){
   if(this._xscale < this.tweenMax){
      this._xscale = this._yscale += this.tweenSpd;
   }else{
      this.onEnterFrame = null;
   }
}

makeDemMovies();

good luck!

Hi!

Where comes r from, the variable the function uses? And can’t I use an instance of a circle from my library called “myCircle” to be duplicated instead of using a method for drawing circles?

THX

Hartwig

the r stands for radius (it could be named anything, r just makes sense), and it’s passed in the brackets when you call the function. in the above code i passed it 50.

yes, you can use any old movie clip you choose, i just wanted to have a 100% code based solution so it was a pure cut and paste.

if the movie is on the stage to begin with, you can just get rid of the part that creates the movie, and the part that deletes it later on. just make sure it’s named correctly.

if you want to attach the clip from your library, just change the part where the circle is created from the method i wrote, to a regular attachMovie call. you can delete it after or leave it on the stage, your call. same thing with the naming.

Hi!

It sounds so logical! But my circles aren’t duplicated. The debugger window only shows on instance and not more. I drew this instance by hand because I got an error with the with-loop which should draw the prototype-circle. This instance is called myCircle but isn’t duplicated. What am I making wrong. I dropped your cool code to frame one but it doesn’t work as we want.

???

Hartwig