Snap to objects type thing

i am making a thing where a bunch of square shaped movie clips will be placed on the desktop, and will be draggable. i was wondering if there was a way to get them to stick together… similar to the snap to objects tool… like say i am dragging one and i want to make a large square out of the smaller squares… i want them to snap together… any ideas?

//Credits: Le Gag / http://www.lolitastudio.net/
MovieClip.prototype.startCDrag = function(GS){
	var c,clip;
	c = this.createEmptyMovieClip("__controller__",1);
	clip = this;
	c.onMouseMove = function(){
		clip._x = Math.round(_root._xmouse / GS)*GS;
		clip._y = Math.round(_root._ymouse / GS)*GS;
	}
}

MovieClip.prototype.stopCDrag = function(){
	delete this.__controller__.onMouseMove;
}
// UTILISATION:
monClip.onPress = function(){
	this.startCDrag(50 ) // constrain to a 50*50 grid
}
monClip.onRelease = monClip.onReleaseOutside = function(){
	this.stopCDrag();
}

pom :slight_smile:

thanks, but im not really sure where to stick the code…and if i need the duplicate code in there or a movie clip even there or whatever… could you lemme know please… thanks…

Here is an Fla using Pom’s code:

thanks… thats awesome… i came up with a different way… but after i duplicated i couldnt get it to work without having to make a seperate variable for each tile duplicated and that would be too much work… and it wouldnt really work anyway… but im wondering if theres a way to duplicate that movie clip and apply the functions to it… im gonna keep trying… but if anyone could help me out that would be great… sorry for all the trouble…

oh… nevermind i got it to work… i just moved stuff around


xSpace=30;
for(i=1;i<=5;i++)
{
	_root.monClip.duplicateMovieClip("monClip"+i,i);
	mc=_root["monClip"+i];
	mc._x = i * xSpace;
	mc._y = 30;
	// UTILISATION:
	mc.onPress = function(){
		this.startCDrag(30);
	}
	mc.onRelease = monClip.onReleaseOutside = function(){
		this.stopCDrag();
	}
}
//Credits: Le Gag / http://www.lolitastudio.net/
MovieClip.prototype.startCDrag = function(GS){
	var c,clip;
	c = this.createEmptyMovieClip("__controller__",1);
	clip = this;
	c.onMouseMove = function(){
		clip._x = Math.round(_root._xmouse / GS)*GS;
		clip._y = Math.round(_root._ymouse / GS)*GS;
	}
}

MovieClip.prototype.stopCDrag = function(){
	delete this.__controller__.onMouseMove;
}

i just gave the duplicated movie clip a variable name and applied the drag and stopdrag functions to it… and changed the startdrag to 30 so it will move the width of the blocks… thanks everyone who helped