# Prevent attachMovie overlapping

**URL:** <https://forum.kirupa.com/t/prevent-attachmovie-overlapping/216213>\
**Category:** flash\
**Created:** [February 14, 2007, 4:08pm UTC](https://forum.kirupa.com/t/prevent-attachmovie-overlapping/216213 "2007-02-14T16:08:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omaha](https://avatars.discourse-cdn.com/v4/letter/o/b5e925/32.png) [@Omaha](https://forum.kirupa.com/u/Omaha)\
**Post date:** [February 14, 2007, 4:08pm UTC](https://forum.kirupa.com/t/prevent-attachmovie-overlapping/216213/1 "2007-02-14T16:08:46Z")

</div>

I have two pencils continuosly making stars and crosses when they are on a certain area. For doing that, I’m using attachMovie. Question is: how do I control the spacing between instances? Right now they overlap each other, and what I like is to be a space equal the size of the stars/shapes.

You can see a live example here: [http://www.speedyshare.com/556221669.html](http://www.speedyshare.com/556221669.html)  
The source file: [http://www.speedyshare.com/971633746.html](http://www.speedyshare.com/971633746.html)

Frame 1

```auto
_root.pencil1.onMouseMove = function() {
if (_root.shape.hitTest(_root.pencil1._x,_root.pencil1._y, true)) {
_root.generateStar();
} 
}
 
_root.pencil2.onMouseMove = function() {
if (_root.shape.hitTest(_root.pencil2._x,_root.pencil2._y, true)) {
_root.generateCross();
} 
}
 
var Count = 0;
 
function generateStar() {
if (Count < 25000) {
Count++;
var currentStar = "star" + Count;
_root.attachMovie("star",currentStar, Count); 
_root[currentStar]._x = _root.pencil1._x; 
_root[currentStar]._y = _root.pencil1._y; 
}
}
 
function generateCross() {
if (Count < 25000) {
Count++;
var currentCross = "cross" + Count;
_root.attachMovie("cross",currentCross, Count); 
_root[currentCross]._x = _root.pencil2._x; 
_root[currentCross]._y = _root.pencil2._y; 
}
}

```

On MC pencil1 (similar for pencil2)

```auto
on (press) {
this.swapDepths(9999)
startDrag(this, true);
gotoAndPlay(2);
}
 
on (release) {
this.swapDepths(8888)
stopDrag();
gotoAndPlay(1);
if (_root.shape.hitTest(_root.pencil2._x,_root.pencil2._y, true)) {
_root.generateCross();
}
    this._x = 100;
    this._y = 200;
}

```

Thanks in advance for your help.
