Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

Restricting transforms between 2 ratios

Recommended Posts

I would like to be able to restrict the tool so it can only be sized between two ratios: (in h:w) 1:1.22 and 1:68.


If the tool is adjusted outside these values, I would like to be able to force constrainScale.


What would be the best way of doing this?


I have hacked the class a bit so I know when the user is dragging a corner handle and a side handle, this way I can make the corners drag in constrained scale and the side handles non-constrained, then I would need to listen to the TransformEvent.SCALE event and act accordingly when they are outside the ratio. Again, I'm not sure how to implement this.


Thanks for any help!

Link to comment
Share on other sites

Probably just listen for a SCALE event and then run your logic in the handler and make any adjustments you need and then make sure you call the updateSelection() (if you make any changes) so that the selection box snaps around things correctly.

Link to comment
Share on other sites

Thanks for the quick reply.


I have done as you say by doing the following:


if (displayObject.scaleX > displayObject.scaleY * 1.22) {
displayObject.scaleX = croppingTool.scaleY * 1.22;


This works perfectly if scaleFromCenter is set to true, unfortunately I need that setting as false. When it's false, the transform manager seems to adjust the displayObjects scale back to another smaller value and then the second time (whilst still dragging the scale control) it reaches the limit it works as expected.


I have attached an FLA to demonstrate this.





Link to comment
Share on other sites

Ah, that's because updateSelection() accepts a single "centerOrigin" parameter that is true by default - just set it to false. updateSelection(false).


To get an optimal behavior, though, you'll probably need to further edit the TransformManager source so that as you move the mouse smaller after the cap has been enforced, it refuses to scale down until the mouse moves beyond where the enforcement started happening. I don't offer free customizations like that, though. You're welcome to take a shot at it yourself. That's why the source code is provided instead of just a .swc.

Link to comment
Share on other sites

Thanks for the solution, the false argument in updateSelection works a treat, I'd have probably bothered to read the docs if I wasn't so under the cosh with this project!


I think I'll leave the customisation due to time constraints but thanks for the hint.


I have to say my colleagues and I are truly grateful for the brilliant work you have done over the years, thanks :)

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.