Blog

a great conversation starts with a great topic

This is a public Blog  publicRSS

Entry

    • Flash AS3 Duplicate Movie Clip
      Entry posted Jan 23 by Dan.Smith
      3165 Views, 0 Comments
      Title:
      Flash AS3 Duplicate Movie Clip
      Entry:

      The easiest way to duplicate a movieClip in Flash AS3 that resides in your library is to first create your clip; then, in the library, right click on it and select Linkage…, and finally check the Export for ActionScript check box.

      Here’s a step by step in case you got lost while doing the initial steps to duplicate your movieClip using AS3.

      1. Create your Clip.  I just made a simple rectangle for an example with a motion tween.

      duplicate clip AS3

      2. Right Click your clip in the library and select “Linkage…” and then check “Export for ActionScript”.

      What this does is make a class called “myMC” that we can now call using actionscript 3.

      3.  Put the following actionscript on frame one of your main timeline:

      addEventListener(MouseEvent.CLICK,makeABox);

      var i:Number = 1; //i will be the total number of boxes

      function makeABox(e:Event):void {
      trace(”new box #” + i);
      var newBox:myMC = new myMC();
      addChild(newBox);
      newBox.x = stage.mouseX;
      newBox.y = stage.mouseY;
      i++;
      }

      So what this all means is, we use addEventListener to listen for a mouse click.  When a mouse click is detected, it runs the function makeABox.  This function calls our new class “myMC” and adds a new child clip using addChild.  We set the X and Y of the clip by detecting the X and Y of the mouse on the stage.

      Here’s a screen shot:

      Flash AS3 helps duplicateMovie

      Here are the source files, happy flash actionscript 3 - ing:

      duplicateMovieAS3.fla

      duplicateMovieAS3.swf