How do you avoid overlapping slices dividing each other?

For anyone interested, this is the command Im using:

var dom = fw.getDocumentDOM();
var webLayerNum = dom.layers.length-1;
var webLayer = dom.layers[webLayerNum].frames[dom.currentFrameNum];
var slicesCount = webLayer.elements.length;
var filepath = fw.browseForFolderURL("Export To", dom.lastExportDirectory);
if (filepath != null){
	var i, slice, name, filename, sXO;
	for (i=0;i<slicesCount;i++){
		slice = webLayer.elements*;
		name = slice.baseName;
		if (name == null) name = "unnamed_slice_"+i;
		filename = filepath + "/" + name;
		sXO = slice.exportOptions;
		if (sXO == null) sXO = dom.exportOptions;
		sXO.crop = true;	
		sXO.cropLeft = slice.left - dom.left;
		sXO.cropRight = slice.left + slice.width - dom.left;
		sXO.cropTop = slice.top - dom.top;
		sXO.cropBottom = slice.top + slice.height - dom.top;
		fw.exportDocumentAs(dom, filename, sXO);
	}
}

If anyone wants I could package it :wink: but I won’t unless some one requests so (I don’t know how many other people would have a use for this - though Its good stuff to me)

…plus it might need tweakin, I don’t know if there are any problems with it or not… could be, never know.