[Extendflash] JSFL AddDataToSelection and Custom Tool problems.
Chris Fourney
c-y-d at rogers.com
Mon May 15 00:06:52 BST 2006
Im trying to make a rotate tool that allows me to click on the end of the symbol and have the symbol rotate by following the mouse.
I have all the proper clicking programming down, and it works perfectly. But when I have it find the angle of rotation based on the previous position, it rotates more or less fine, doesnt exactly follow the mouse as it moves, but the big problem is that as I rotate it around - the whole symbol begins to shrink the more I rotate it.
Heres the code. I get the angle of rotation by using atan2. Since atan is from the origin, I take the angle of the new click, and I subtract the old click from it. This in theory should give me the new angle at which I should rotate it to match up with the mouse's position.
--The start position is initially set in the mousedown function, this is called in the mousemove function within the clicking area.
penPointx = fl.tools.penLoc.x;
penPointy = fl.tools.penLoc.y;
mat = fl.getDocumentDOM().selection[0].matrix;
relativex = penPointx - mat.tx;
relativey = (-1)*(penPointy - mat.ty);
srelativex = startPointx - mat.tx;
srelativey =(-1)*(startPointy - mat.ty);
firstAngle = Math.atan2(srelativey, srelativex);
secondAngle = Math.atan2(relativey, relativex);
deg = (-1)*(secondAngle - firstAngle);
deg = (deg * 180)/Math.PI;
fl.getDocumentDOM().rotateSelection(deg)
var transPoint = fl.getDocumentDOM().getTransformationPoint();
mat = fl.getDocumentDOM().selection[0].matrix;
xpos = mat.tx + transPoint.x;
ypos = mat.ty + transPoint.y; //Finding the transform point's location on the outside
startPointx = fl.tools.penLoc.x;
startPointy = fl.tools.penLoc.y;
Apart from that -- Im using another function I wrote up in order to rotate a different piece on the stage based on a given x,y position.
the function is fed the element's layer number, the element number, the x,y value of the rotation point, and the amount at which to rotate it in degrees -- and uses the const method for matrices to put the transofrmation onto the desired matrix.
It works great when its ran as a command, but as soon as I run it as a function within a tool, it makes the tx and ty of the symbol jump around absolutely everywhere.
------------
function rotateAt(lay, elem, xval, yval, deg){
deg = (deg * Math.PI)/180;
var CurrFrame = fl.getDocumentDOM().getTimeline().currentFrame;
matDEGChanger = fl.getDocumentDOM().getTimeline().layers[lay].frames[CurrFrame].elements[elem].matrix;
aval = Math.cos(deg);
bval = Math.sin(deg);
cval = (Math.sin(deg) * (-1));
dval = Math.cos(deg);
matDEGChanger.a = aval;
matDEGChanger.b = bval;
matDEGChanger.c = cval;
matDEGChanger.d = dval;
xpt = ((yval/dval)-(xval/cval))/((bval/dval)-(aval/cval));
ypt = ((xval/aval)-(yval/bval))/((cval/aval)-(dval/bval));
xtrace = (Math.cos(deg) * xpt) - (Math.sin(deg) * ypt);
ytrace = (Math.sin(deg) * xpt) + (Math.cos(deg) * ypt);
matDEGChanger.tx = xpt;
matDEGChanger.ty = ypt;
mat = fl.getDocumentDOM().getTimeline().layers[lay].frames[CurrFrame].elements[elem].matrix;
newMat = fl.Math.concatMatrix(mat, matDEGChanger);
fl.getDocumentDOM().getTimeline().layers[lay].frames[CurrFrame].elements[elem].matrix = newMat;
}
Im really confused, theres no reason for the rotation to make the symbol shrink. And the command with the rotateAtPt function works as a command, but not in a tool.
Any help is appreciated. Thanks.
-Chris
Any help would be great.
-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.flashguru.co.uk/pipermail/extendflash/attachments/20060514/ae3f4796/attachment.htm
More information about the Extendflash
mailing list