JSFL - Element.rotation is NaN

818 Views Asked by At

I'm writing an exporter in JSFL, to export Flash animations into a format that can be replayed in a custom player. The exporter basically iterates through the timeline and through all the elements at each keyframe, and writes out information about the element, including its position, rotation, scale, etc.

I have a problem with getting the rotation out of certain elements, it comes out as NaN. The most common cause of this is if an element has been flipped (Modify->Transform->Flip Horizontal), although I think it can happen in other circumstances as well. Up until now I've got around the problem by writing out someElement.skewX instead of someElement.rotation if someElement.rotation is NaN (See here for some of my related code, which also tries to detect if flipping has occurred).

This has worked so far because in those cases the skewX value is the same as the value I'd expect for the rotation. But now I want the exporter to be able to handle exporting elements which are skewed as well as rotated, so I really need to have proper values for the rotation. How can I extract proper rotation values from Flash? Is there something I can do to get rotation values out of the matrix, or to stop rotation from being NaN in the first place?

1

There are 1 best solutions below

0
On

I found a way to get the rotation angle from the object's matrix.

element = someobject;
//Angle in radians
var angle = Math.atan2(element.matrix.b, element.matrix.a);
//convert to degrees
var degrees = angle * 180 / Math.PI;

I am not sure this takes into account if the object is skewed.

extract angle from rotation matrix (inkscapeforum.com)