Just great! yet another weird Flash “feature”. When I tried to get the width of a rotating MovieClip I got wildly variating values. This surprised me because the MovieClip only contained exact round shape. The circle was 25 px in diameter, but when I started to trace the width in an interval I got values ranging from 25 to 35.4px.
As it turned out, the width and height of the MovieClip only represent the bounding box of the original shape (when it still had a rotation of 0). The only way to get the actual width and height of the MovieClip was to use the getBoundsmethod. This method calculates the boundingbox according to the current shape and orientation of the MovieClip giving the trrue width and height.
To test this create a movieclip width a circle in it and place the code below on the first frame (I’m no fan of timeline-code but it’s ideal for testing purpose
).
1 2 3 4 | this.onEnterFrame = function(){ this._rotation += 15; trace("boundingbox-width: "+(this.getBounds().xMax-this.getBounds().xMin)+"\t\twidth: "+this._width); } |
The sample is as2 but the problem and solution are the same in as3.
I hope this helps some of you who were wondering why a 25px circel suddenly had a 35.4px width
.


