Hello,

I have an application where any uicomponent is draggable relative to the
stage. The code is the same for each one. Does anyone have a suggestion on a
clean way of enabling that functionality for any uicomponent while
minimizing duplication? Here is a snippet of the main (duplicate) dragging
logic:

private function drag(event:MouseEvent):void
{
    var snapIt:Boolean = false;
 var distanceX:int = (stage.mouseX - xPosStart);
var distanceY:int = (stage.mouseY - yPosStart);
 if ((snapIt)&&((distanceX != 0)||(distanceY != 0))) {
var snapTo:int = 15;
 var xMove:int = xStart+distanceX;
var yMove:int = yStart+distanceY;
 var xSnap:int = xMove + (snapTo - xMove % snapTo);
var ySnap:int = yMove + (snapTo - yMove % snapTo);
 this.x=xSnap;
this.y=ySnap;
 } else {
this.x=xStart+distanceX;
this.y=yStart+distanceY;
 }
    event.updateAfterEvent();
}

Reply via email to