Limitador rectangular sin condicionales
Un método super sencillo para aplicar un límite rectangular a un elemento arrastrable (si no te va bien utilizar startDrag):
Actionscript:
-
arrastrable.x = Math.min( Math.max(limite.x,arrastrable.x), limite.width-arrastrable.width );
-
arrastrable.y = Math.min( Math.max(limite.y,arrastrable.y), limite.height-arrastrable.height );
Un ejemplo de implementación en AS2:
Actionscript:
-
import flash.geom.Rectangle;
-
import mx.utils.Delegate;
-
-
var limite:Rectangle = new Rectangle (100, 100, 200, 100);
-
arrastrable.onPress = Delegate.create (this, start_drag);
-
arrastrable.onRelease = arrastrable.onReleaseOutside = Delegate.create (this, stop_drag);
-
function start_drag ()
-
{
-
arrastrable.onEnterFrame = Delegate.create (this, doDrag);
-
}
-
function stop_drag ()
-
{
-
arrastrable.onEnterFrame = null;
-
}
-
function doDrag ()
-
{
-
arrastrable._x = _xmouse;
-
arrastrable._y = _ymouse;
-
arrastrable._x = Math.min (Math.max (limite.x, arrastrable._x), (limite.x + limite.width) - arrastrable._width);
-
arrastrable._y = Math.min (Math.max (limite.y, arrastrable._y), (limite.y + limite.height) - arrastrable._height);
-
}
November 17, 2007 | Filed Under ActionScript | 2 Comments











