# Creating mask over duplicates

**URL:** <https://forum.kirupa.com/t/creating-mask-over-duplicates/215821>\
**Category:** Uncategorized\
**Created:** [February 10, 2007, 9:49pm UTC](https://forum.kirupa.com/t/creating-mask-over-duplicates/215821 "2007-02-10T21:49:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![electricgarden](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@electricgarden](https://forum.kirupa.com/u/electricgarden)\
**Post date:** [February 10, 2007, 9:49pm UTC](https://forum.kirupa.com/t/creating-mask-over-duplicates/215821/1 "2007-02-10T21:49:21Z")

</div>

Hi, I am having trouble creating duplicates of a movieclip that stay behind a mask. They keep overriding the layering/masking and end up on top of the mask. The script is below, where “sman” is the mask and “sf1” is the movieclip that’s being duplicated. Any help appreciated, thank you!

//import the Tween, Easing classes:  
import mx.transitions.Tween;  
import mx.transitions.easing._;  
stop();  
// ----------function to generate a random number  
function randRange(min:Number, max:Number):Number {  
var randomNum:Number = Math.round(Math.random()_(max-min))+min;  
return randomNum;  
}

snowman\_mc.\_visible=true;

button2\_mc.onRelease = function() {  
//make 20 duplicates of sf1\_mc and randomly distribute on stage  
for (i=1; i\<=50; i++) {  
duplicateMovieClip(sf1\_mc, “sf1”+i, this.getNextHighestDepth()+i);  
//duplicateMovieClip(sman\_mc, “sman”+i, this.getNextHighestDepth()+j);  
//set mask  
\_root[“sf1”+i].setMask(“sman”+i);  
//move them to random x and y  
//\_root[“sman”+i].\_x = 600;  
//\_root[“sman”+i].\_y = 400;  
\_root[“sf1”+i].\_x = randRange(300, 600);  
\_root[“sf1”+i].\_y = randRange(300, 400);  
//random scaling x and y to same value  
//var newScale = randRange(10, 100);  
//\_root[“sf1”+i].\_xscale = newScale;  
//\_root[“sf1”+i].\_yscale = newScale;  
//tween them  
//new Tween(\_root[“sf1”+i], “\_x”, Back.easeIn, \_root[“sf1”+i].\_x, 30, 1, true);  
//new Tween(\_root[“sf1”+i], “\_y”, Back.easeIn, \_root[“sf1”+i].\_y, 30, 1, true);  
};  
}
