PDA

View Full Version : Defining a rectangle boundary......



SX1Dude
July 1st, 2003, 07:06 AM
Hi,

I have drawn a rectangle area in which I want to drag a copy of a MC instance from outside the rectangle.

1. I want to be able to define the rectangle as a boundary so that I can drag and drop a copy of the instance from outside the rectangle to inside the rectangle. If the MC instance is dropped outside the rectangle then the MC instance snaps back to it's original position.

2. Once the MC instance has been dragged and dropped inside the rectangle it can be dragged and moved around BUT only inside the rectangle and not outside it.

Any idea's ?

jingman
July 1st, 2003, 12:08 PM
Untested, and prolly not the best way to do it, but maybe a way.


tester = new Object();
tester.inbox = function(myMC){

boxminx = box._x - box._width/2;
boxmaxx = box._x + box._width/2;
boxminy = box._y - box._height/2;
boxmaxy = box._y + box._height/2;

if(myMC._x > boxminx && myMC._x < boxmaxx && myMC._y > boxminy && myMC._y < boxmaxy){
return(true);
}else{
return(false);
};
};

on(press){
if(tester.inbox(this) == true){
startDrag(this,<bounds of box>);
}else{
startDrag(this);
};
};

on(release){
if(tester.inbox(this) == false){
this._x = startingx;
this._y = startingy;
};
};

jingman
July 1st, 2003, 01:22 PM
Sure, later today.

radicaljugnu
July 1st, 2003, 01:32 PM
chek this fla

SX1Dude
July 1st, 2003, 02:06 PM
This is half of the solution, once the instance has been dropped inside the square it should not be able to be dropped outside the square.

Like the snap back if not in square thought !

Can you show me the other half ?

Thanks

:eye:

jingman
July 1st, 2003, 05:23 PM
I believe this will do exactly what you want.