[as3] function resetStartProps():Void {
delete _startProps; //Aids in memory management
_startProps = {};
var sp = _startProps;
var axisPoint_obj = this.axisPoint;
var mdx = _targetObject._parent._xmouse – axisPoint_obj.x; //Distance to mouse along the x-axis
var mdy = axisPoint_obj.y – _targetObject._parent._ymouse; //Distance to mouse along the y-axis
var md = Math.sqrt(mdx * mdx + mdy * mdy); //Total distance to mouse
var angleAxisToMouse = Math.atan2(mdy, mdx);
var rdx = _targetObject._x – axisPoint_obj.x; //Distance between axis point and registration along the x-axis
var rdy = axisPoint_obj.y – _targetObject._y; //Distance between axis point and registration along the y-axis
var angle = _targetObject._rotation * (Math.PI / 180); //rotation translated to radians
var rAngleAxisToMouse = angleAxisToMouse + angle; //Rotated (corrected) angle to mouse (as though we tilted everything including the mouse position so that the _targetObject is at a 0 degree angle)
sp.centerX = this.centerX;
sp.centerY = this.centerY;
sp.axisX = axisPoint_obj.x;
sp.axisY = axisPoint_obj.y;
sp._x = _targetObject._x;
sp._y = _targetObject._y;
sp._xscale = _targetObject._xscale;
sp._yscale = _targetObject._yscale;
sp._rotation = _targetObject._rotation;
sp.angle = angle;
sp._xmouse = _targetObject._parent._xmouse;
sp._ymouse = _targetObject._parent._ymouse;
sp.angleAxisToMouse = (angleAxisToMouse + Math.PI * 2) % (Math.PI * 2);
sp.distAxisToMouseX = Math.cos(rAngleAxisToMouse) * md;
sp.distAxisToMouseY = Math.sin(rAngleAxisToMouse) * md;
sp.distAxisToMouse = md;
sp.distRegToCenterX = _targetObject._x – sp.centerX;
sp.distRegToCenterY = _targetObject._y – sp.centerY;
sp.distAxisToReg = Math.sqrt(rdx * rdx + rdy * rdy);
sp.angleAxisToReg = Math.atan2(rdy, rdx);
if (_bounds.xMax != undefined) { //If we need to constrain dragging to stay within a rectangle…
var bnds = _targetObject.getBounds(_targetObject._parent);
sp.xMin = _bounds.xMin + (_targetObject._x – bnds.xMin) + 1;
sp.xMax = _bounds.xMax – (bnds.xMax – _targetObject._x) – 1;
sp.yMin = _bounds.yMin + (_targetObject._y – bnds.yMin) + 1;
sp.yMax = _bounds.yMax – (bnds.yMax – _targetObject._y) – 1;
sp.angleAxisToTL = (Math.atan2(_bounds.yMin – axisPoint_obj.y, _bounds.xMin – axisPoint_obj.x) + (Math.PI * 4)) % (Math.PI * 2);
sp.angleAxisToTR = (Math.atan2(_bounds.yMin – axisPoint_obj.y, _bounds.xMax – axisPoint_obj.x) + (Math.PI * 4)) % (Math.PI * 2);
sp.angleAxisToBR = (Math.atan2(_bounds.yMax – axisPoint_obj.y, _bounds.xMax – axisPoint_obj.x) + (Math.PI * 4)) % (Math.PI * 2);
sp.angleAxisToBL = (Math.atan2(_bounds.yMax – axisPoint_obj.y, _bounds.xMin – axisPoint_obj.x) + (Math.PI * 4)) % (Math.PI * 2);
}
}
/**********************************************/
/* get-set Function */
/**********************************************/
function get centerX():Number {
return this.centerPoint.x;
}
function get centerY():Number {
return this.centerPoint.y;
}
function get centerPoint():Object {
var p = {x:_localCenterX, y:_localCenterY};
_targetObject.localToGlobal(p);
_targetObject._parent.globalToLocal(p);
return p;
}
function get axisX():Number {
return this.axisPoint.x;
}
function get axisY():Number {
return this.axisPoint.y;
}
function get axisPoint():Object {
var p = {x:_localAxisX, y:_localAxisY};
_targetObject.localToGlobal(p);
_targetObject._parent.globalToLocal(p);
return p;
}
/*****************************************************************************/
/* */
/* This is the function to find the relative center Point */
/* */
/*****************************************************************************/
function resetCenterPoint():Void {
var rotation_num = _targetObject._rotation;
_targetObject._rotation = 0; //We need to straighten it temporarily to measure accurately…
var bounds_obj = _targetObject.getBounds(_targetObject._parent);
var x1 = (bounds_obj.xMax + bounds_obj.xMin) / 2; //Find the center x-coordinate when the rotation is 0
var y1 = (bounds_obj.yMax + bounds_obj.yMin) / 2; //Find the center y-coordinate when the rotation is 0
var dx = x1 – _targetObject._x; //distance between the _targetObject’s registration point and center point along the x-axis
var dy = _targetObject._y – y1; //distance between the _targetObject’s registration point and center point along the y-axis
var radius = Math.sqrt((dx * dx) + (dy * dy)); //Find the distance between the _targetObject’s registration point and the center point.
var angle1_num = Math.atan2(dy, dx);
var angle = (rotation_num * (Math.PI / 180)) – angle1_num; //Total angle that we’re adding/moving (we have to subtract the original angle to just get the difference)
var x = _targetObject._x + (Math.cos(angle) * radius);
var y = _targetObject._y + (Math.sin(angle) * radius);
_targetObject._rotation = rotation_num; //Re-apply the rotation since we removed it temporarily.
var p = {x:x, y:y};
_targetObject._parent.localToGlobal(p);
_targetObject.globalToLocal(p);
_localCenterX = p.x;
_localCenterY = p.y;
}
/*****************************************************************************/
/* */
/* This is the function to find the relative X Y */
/* */
/*****************************************************************************/
function setAxis(x:Number, y:Number):Void { //x and y according the the _targetObject._parent’s coordinate space!
var p = {x:x, y:y}; //Make a point so that we can do localToGlobal()
_targetObject._parent.localToGlobal(p); //Translates the coordinates to global ones (based on _root)
_targetObject.globalToLocal(p); //Translates the coordinates to local ones (based on _targetObject)
_localAxisX = p.x;
_localAxisY = p.y;
}
[/as3]