Jump to content
Search Community

Constraining scaling [SOLVED]

dave test
Moderator Tag

Recommended Posts

Hi there,

Ok basically when I add items to my TransformManager, I place them there at 70% but I want to stop the user from scaling them past 100% (and probably stop them scaling them lower than 20% or so too). So far, I haven't seen a property which lets me specify a restriction like this so I thought about using the TransformEvent.SCALE event. However, it just seems to execute once, when the mouse is released. My plan was to check for the scale being greater than 1 and if it is, setting it to 1 but if this event is only fired on release, that's not going to happen.

 

So yeah, basically I'm wondering what approach you would take to this. Is there a parameter lurking somewhere that would just sort this for me? If not, it would be a nice addition to TM as I think a lot of people would like to stop their images from being scaled higher than 100%, degrading the image quality. Maybe a MaxScale/MinScale type option...

Link to comment
Share on other sites

Wish granted. :)

 

I just added the ability to set minScaleX, maxScaleX, minScaleY, and maxScaleY properties to TransformItem instances in version 1.2. You should have received an e-mail about the update with instructions about how to get it this morning.

 

Enjoy!

Link to comment
Share on other sites

Hi, this sounds great but for some reason, I'm not seeing how I can add this functionality into my app. I'm pretty sure I'm just having a bit of "first day back to work" stupidity but...

The way I'm using TM at the moment is to create a new movieclip object, then simply "transformManager.addItem(myMC);" which works but, as far as I can see, these new properties are available only when creating a new "TransformItem" instance, which I can do fine. However, how do I then actually add a TransformItem to my TransformManager? The transformManager.addItem() only accepts DisplayObjects!

Again, forgive my stupidity. I'm sure it's very simple but I don't think my coffee's kicked in yet... :(

Link to comment
Share on other sites

Sip the coffee....let the caffeine kick in....

 

Feeling better?

 

Okay, good question. addItem() returns a TransformItem, so you can just use that to add the min/max scale, like so:

 

var myItem:TransformItem = myManager.addItem(myDisplayObject);
myItem.setScaleConstraints(0.5, 1, 0.5, 1);

//or set them directly if you don't want to use the setScaleConstraints();
myItem.minScaleX = 0.5;
myItem.maxScaleX = 1;
myItem.minScaleY = 0.5;
myItem.maxScaleY = 1;

 

You can also get the TransformItem associated with your DisplayObject anytime using the getItem() method, like:

 

var myItem:TransformItem = myManager.getItem(myDisplayObject);

 

(that assumes you've already used the addItem() at some point to add the DisplayObject to the TransformManager instance)

 

Does that clear things up?

Link to comment
Share on other sites

Aha! The secret was that I don't actually "create" a TransformItem myself. addItem was actually returning one for me! Clever...

Anyways yes, that works awesome now and I think it's a great addition to the featureset. Greatly appreciated...

Link to comment
Share on other sites

Ah, this new feature is great but there's a bug I've just noticed...

First off, I've got my minimum scales set to 0.2, my max to 1 and images are set to 0.7 scale before being added to the TransformManager. Anyways, if I add an item, rotate it 180 degrees clockwise, then resize using the handles on the left of the screen (on the right if it's at 0 degrees rotation), it snaps to the minimum scale in the 0 degrees rotation position. Any ideas?

Link to comment
Share on other sites

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...