# Draw square 2 select object onstage drag the selected objects around.\[OPTIMISE PLS\]

**URL:** <https://forum.kirupa.com/t/draw-square-2-select-object-onstage-drag-the-selected-objects-around-optimise-pls/295982>\
**Category:** flash\
**Created:** [September 8, 2009, 10:51am UTC](https://forum.kirupa.com/t/draw-square-2-select-object-onstage-drag-the-selected-objects-around-optimise-pls/295982 "2009-09-08T10:51:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adBuryD](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@adBuryD](https://forum.kirupa.com/u/adBuryD)\
**Post date:** [September 8, 2009, 10:51am UTC](https://forum.kirupa.com/t/draw-square-2-select-object-onstage-drag-the-selected-objects-around-optimise-pls/295982/1 "2009-09-08T10:51:41Z")

</div>

[COLOR=DarkRed]\*Below is the code for drawing a square to select MULTIPLE items on stage , then drag the selected items around the stage… Some problems arise while dragging the movieclips lag behing a little if we drag faster… Also NEED TO KNOW IF THIS COULD BE OPTIMISED AS I FEEL THE CODE IS VERY SHABBY!:azn: THANKS IN ADVANCE.  
i AM TRYING TO DO THIS IN AS 3.O WILL PASTE IT ONCE IT IS DONE… AS3.0 KEEPS GIVING ME ALL SORTS OF ERRORS:hangover:.

jUS cOPY pASTe tHE COde AND cHK\*[/COLOR]

[COLOR=Blue]\_root.Idtemp = [];  
\_root.allow = true;  
\_root.temp = [];  
\_root.createEmptyMovieClip(“mcy”,1);  
\_root.createEmptyMovieClip(“mc”,2);  
with (\_root.mcy) {  
mcy.lineStyle(1,0x000000,100);  
mcy.moveTo(100,100);  
mcy.beginFill(0xcccccc,50);  
mcy.lineTo(100,120);  
mcy.lineTo(210,120);  
mcy.lineTo(210,100);  
mcy.lineTo(100,100);  
mcy.endFill();  
}  
for (i=0; i\<5; i++) {  
\_root.mcDup = \_root.mcy.duplicateMovieClip(‘mcy’+i, i\*4);  
\_root.mcDup.\_y = \_root[‘mcy’+(i-1)].\_y+30;  
\_root.mcDup.Id = i;  
temp.push(\_root.mcDup);  
}  
mc.onMouseDown = function() {  
if (\_root.allow == true) {  
var sx = \_xmouse;  
var sy = \_ymouse;  
mc.onMouseMove = function() {  
mc.clear();  
var ex = \_xmouse;  
var ey = \_ymouse;  
mc.lineStyle(1);  
mc.beginFill(0xffccff,30);  
mc.moveTo(sx,sy);  
mc.lineTo(sx,sy+(ey-sy));  
mc.lineTo(ex,ey);  
mc.lineTo(sx+(ex-sx),sy);  
mc.lineTo(sx,sy);  
mc.endFill();  
};  
}  
};  
\_root.mc.onMouseUp = function() {  
\_root.allow = false;  
for (j=0; j\<temp.length; j++) {  
if (mc.hitTest(temp[j])) {  
\_root.Idtemp.push(temp[j]);  
\_root.Idtemp[j].selected = true;  
}  
\_root.Idtemp.sort(Array.NUMERIC);  
}  
\_root.Idtemp[0].onPress = function() {  
this.startDrag();  
\_root.Idtemp[0].onEnterFrame = function() {  
for (k=0; k\<Idtemp.length; k++) {  
Idtemp[k].\_x = Idtemp[k-1].\_x;  
Idtemp[k].\_y = Idtemp[k-1].\_y+30;  
updateAfterEvent();  
}  
};  
mc.clear();  
\_root.mc.onMouseMove = null;  
};  
\_root.Idtemp[0].onRelease = function() {  
\_root.Idtemp[0].onEnterFrame = null;  
this.stopDrag();  
\_root.Idtemp = [];  
\_root.allow = true;  
};  
mc.clear();  
\_root.mc.onMouseMove = null;  
};  
removeMovieClip(\_root.mcy);[/COLOR]
