blank blank blank blank blank
blank       blank
blank  

.:|:. home .:|:. resources .:|:. links .:|:. contact .:|:.
  blank
blank       blank
blank
blank       blank
blank  
Movieclip Duplication

// The following is used for duplicating movie clips and applying various actions to them.
// All references are local so it can be used on any timeline.
clipFunctions = function ()
    {
    // Initialize position and / or variables.
    // "clipIncrement" will equal the current "i" value passed from the "for" loop found below that is used to create the clips.
    // Note that when used inside a movie clip, x = 0 and y = 0 will be in the center of the container clip regardless of the clips
    // placement on the main stage.
    // If the clips are created on the the main stage, or "_root", x = 0 and y = 0 will be in the upper left corner of the main movie.
    // Flash "y" direction + /- values are opposite from a graphs in that y increases as you go farther down.
    this.init = function(clipIncrement)
        {
        this._x = this._width * clipIncrement;
        this._y = this._height * clipIncrement;
        // The movie is 450px x 450px.
        this.xLimit = 225 - (this._width / 2);
        this.yLimit = 225 - (this._height / 2);
        }
    //****************************************************
    // For "onEnterFrame" actions if needed.
    this.move = function()
        {
        this._x += 4;
        this._y += 4;
        if(this._x > this.xLimit)
            {
            this._x = this.xLimit * -1;
            }
        if(this._y > this.yLimit)
            {
            this._y = this.yLimit * -1;
            }
        }
    //****************************************************
    // Button actions if needed.
    this.buttonPress = function()
        {
        removeClips();
        }
    }
//****************************************************
setClips = function ()
    {
    for (i = 0; i < 10; i++)
        {
        // To use attachMovie, right click the desired clip in the Library, select Linkage, name it (named below as "clipExport"),
        // and check the "Export for actionscript" and "Export in first frame" checkboxes.
        // The linkage name can be the same as the clip's name in the library or a different one.
        // Usually this is the better way to go since you don't have to have a clip on stage to duplicate, and you can use the
        // "removeMovieClip" method on the clip instances.
        // Each clip will need a unique instance name, assigning the name to a variable will simplify later references to it.
        // The end result will be 10 clips named "clipExport0" through "clipExport9".
        name = "clipExport" + i;
        // Note that "this" as used here refers to the current timeline, All other uses (except in the removeClips() function)
        // refer to individual clips.
        this.attachMovie("clipExport", name, i);
        // This alternate way will duplicate a clip on the stage with an instance name of "clip" but you won't be able to use
        // "removeMovieClip" on them.
        //name = "clip"+i;
        //this.clip.duplicateMovieClip(name, i);
        clipFunctions.apply(this[name]);
        // Initiate the clips and pass the current value of "i" to the init() function.
        this[name].init(i);
        // Apply event handlers as needed.
        this[name].onEnterFrame = this[name].move;
        this[name].onPress = this[name].buttonPress;
        }
    // Used with duplicateMovieClip to hide the original clip being duplicated.
    // It is usually better to hide a clip than to apply the same functions the "for" loop did to the duplicates because the
    // name won't be "numerically inline" with the others and can make later references to the clip a pain.
    // An advantage of duplicateMovieClip is that you can use the clip on stage for laying out the placement of the rest
    // of the clips.
    // If the setClips() function is called more than once, enter the line "this.clip._visible = true;" above the "for" loop.
    //this.clip._visible = false;
    }
//****************************************************
// Called by the button handler, this will remove the clips from the stage.
removeClips = function ()
    {
    for (i = 0; i < 10; i++)
        {
        name = "clipExport" + i;
        if(this[name])
            {
            removeMovieClip(this[name]);
            }
        }
    }
//****************************************************
setClips();

Results of above code, clicking a clip removes the clips:

  blank
blank       blank
blank
blank       blank
blank     blank
blank       blank
blank blank blank blank blank