Jump to content
Search Community

Getting targetObject's scaled width and height [SOLVED]

motionsmith
Moderator Tag

Recommended Posts

motionsmith
Posted

Hello,

 

I am needing to read the width and height of a transformItem as if it were not rotated. The .width and .height property seem to take the rotation into account, meaning that I get the value that I need only when rotation == 0.

 

I figured I might be able to get this value from the bounds.width/height value, but I am trying to read the value when the transformItem is NOT selected, in which case "bounds" seems to be null. Is there an explicit value for this, or do I need to perform a calculation. If so, what is it?

motionsmith
Posted

I got a close value by taking the scaleX/scaleY value of the transformItem and multiplying it by my display object's original size. The calculation isn't perfect though. If my display object is 100x100, when I rotate it, it will become. 99.XXXXXXXXXX.

 

This is okay I think, unless you know a way to get a perfect reading. (by that, I mean that when I rotate it, the width and height STAY 100).

motionsmith
Posted

Nevermind, that didn't work either. The scaleX and scaleY must reset themselves after they are deselected. Any hints?

Posted

Use my MatrixTools class and try something like this:

 

function getUnrotatedWidth($mc:DisplayObject):Number {
   var bounds:Rectangle = $mc.getBounds($mc);
   return bounds.width * MatrixTools.getScaleX($mc.transform.matrix);
}

function getUnrotatedHeight($mc:DisplayObject):Number {
   var bounds:Rectangle = $mc.getBounds($mc);
   return bounds.height * MatrixTools.getScaleY($mc.transform.matrix);
}

motionsmith
Posted

Close enough! Solved, thanks!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...