Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stopping drag on control press?

Status
Not open for further replies.

DGTLguy

Technical User
Jul 23, 2003
125
US
i have a square sprite that i want to be draggable onPress, and nondraggable when the control but is pressed? also rotatable when control is pressed. help please....
 
the answer to my own question...

stop();

box_mc.onPress = function() {
// if the CTRL key is down, rotate the clip
if (Key.isDown(Key.CONTROL)) {
// calculate the offset angle necessary to avoid "jumping"
xdiff = _root._xmouse-box_mc._x;
ydiff = _root._ymouse-box_mc._y;
offset = Math.atan2(ydiff, xdiff)*180/Math.PI-this._rotation;
// set the sprite enterframe event for regular processing
this.onEnterFrame = function() {
// make the sprite point at the mouse
xdiff = _root._xmouse-box_mc._x;
ydiff = _root._ymouse-box_mc._y;
angle = Math.atan2(ydiff, xdiff)*180/Math.PI;
// use the offset angle to avoid "jumping"
box_mc._rotation = angle-offset;
}
// if the CTRL key is up, drag the clip
} else {
this.startDrag (false);
}
}


box_mc.onRelease = function() {
// stop dragging
stopDrag();
// stop rotating
delete this.onEnterFrame;
}


box_mc.onReleaseOutside = function() {
// stop rotating
delete this.onEnterFrame;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top