Problem with move constraints and negatively sized objects

39 views
Skip to first unread message

Royce

unread,
Oct 5, 2011, 10:32:54 PM10/5/11
to Flex ObjectHandles
I'm using OH2 and having a problem with move constraints and
negatively sized objects (ie. negative width and/or height). Here's my
constraint code:

var moveConstraint:MovementConstraint=new MovementConstraint();
moveConstraint.minX=0;
moveConstraint.minY=0;
moveConstraint.maxX=maskLayer.width;
moveConstraint.maxY=maskLayer.height;
// We must bind the maxX and maxY to the maskLayer dimensions in case
it is resized, we
// need the constraint to be updated.
BindingUtils.bindProperty(moveConstraint,"maxX",maskLayer,"width");
BindingUtils.bindProperty(moveConstraint,"maxY",maskLayer,"height");
objectHandles.addDefaultConstraint(moveConstraint);
objectHandles.addMultiSelectConstraint(moveConstraint);

I want to stop objects from being moved or resized outside their
parent canvas (maskLayer). This code works beautifully for objects
that were created by dragging down/right (ie. have positive width/
height). But if you drag up/left when creating a new object, the
constraint no longer applies and you can move/size the object outside
of maskLayer.

Is there an easy fix/workaround? I'm thinking of not using constraints
at all and doing my own constraints in the PropertyChangeEvent handler
of my display component.

Andriy Sokolov

unread,
Oct 6, 2011, 5:36:44 AM10/6/11
to object...@googlegroups.com
Royce,
the problem that you describe is unknown for me. I developed a tool for sizing/removing/rotating of nested objects and used constraints in the same way as you, and it worked well (for unrotated objects). The problem is somwhere else.

Royce

unread,
Oct 7, 2011, 4:34:11 AM10/7/11
to Flex ObjectHandles
The problem lies in the MoveConstraint class. It assumes normalised
objects, ie. with positive width and height. If you have objects with
negative widths/heights, it doesn't work as expected. Actually object
handles gets confused with such objects. The HandleDescriptions also
get confused. I worked around it by normalising my objects before
registering them with ObjectHandles and imposing a size constraint so
that they cannot be resized so that they end up with a negative width/
height.
Reply all
Reply to author
Forward
0 new messages