# Drag selection, and click anywhere tutorial

• 05-04-2009, 04:59 PM
congruent2006
Drag selection, and click anywhere tutorial
I know someone here HAS got to know THIS one.

Ive seen it before and now i cant find it, why does that always happen to me?

Tutorial that tells you how to click anywhere on the screen,
and or tutorial that tells you how to click drag, and make a square to select multiple units for strategy type game and what not.
• 05-05-2009, 08:22 PM
Pazil
Come on! Figure it out, you must know some basic math!
• 05-06-2009, 12:40 AM
congruent2006
what does that have to do with anything?

nevermind i suppose i will try to google it again
• 05-06-2009, 12:50 AM
bluemagica
its quite simple actually! get the point where mouse is clicked, and where mouse is released. Then use a for loop to go through your instances and check if they are within the area!

By the way, are you using as2 or as3?
• 05-06-2009, 01:03 AM
congruent2006
as2
• 05-06-2009, 01:20 AM
ImprisonedPride
Seriously congruent, you've got to start meeting us 1/2 way on these topics. Seems like your trying less because we're available to answer questions on this forum. On to your question...

You can basically do this by activating a start/stop drag scenario and keeping track of those start/end points on the screen. Once the user has released the mouse to complete the square, cycle through your units and check if they are inside the square.

Code:

```dragging = false; checkit = false; startPt = {}; endPt = {}; onMouseDown = function() {     dragging = true;     startPt.x = _xmouse;     startPt.y = _ymouse; } onMouseUp = function() {     dragging = false;     checkit = true;     endPt.x = _xmouse;     endPt.y = _ymouse; } onEnterFrame = function() {     if (!dragging and checkit) {           // cycle through objects and see if they are between startPt and endPt           checkit = false;     } }```
• 05-06-2009, 01:42 AM
congruent2006
Thanks.

i TOLD you i would google it, noone forced you to help me,
and how am i suppose to meet halfway on something i dont know how to do?
• 05-06-2009, 02:55 AM
samvillian
By trying to figure it out.... wow... you are basically telling IP that he wasted his time in trying to help out a friend (relatively speaking).

I would advise you to scan through the code, and code it yourself, and check whether you implemented all the steps right. Shouldn't be hard since its basic code. idk.

so ya to sum up, don't make people feel bad for helping you... lol..

meet halfway by saying I got this far, i just need to know how to check blah blah blah.

@IP, those cig's are getting expensive i see lol. march 15th, very nice. I've never smoked in my life (except hookah) lol.

nicotine... mmmmmmm nicotine.... lol.. fight the urge... nicotine...
__________________
If the only tool you have is a hammer, you tend to see every problem as a nail.
• 05-06-2009, 08:24 AM
Squize