Apache flex 在flex中旋转绘制的矩形

Apache flex 在flex中旋转绘制的矩形,apache-flex,Apache Flex,我编写了以下用于绘制旋转矩形的代码 var s:UIComponent = new UIComponent(); s.graphics.lineStyle(1, 0x0000FF); s.graphics.drawRect(50, 50, 200, 200); s.rotation = 30; template.addChild(s); 其中,模板是画布。它的旋转很好,但问题是位置不正确。i、 e.旋转后不在(50,50)内。我怎样才能解决这个问题 提前谢谢 您看到的是Flex中围绕原

我编写了以下用于绘制旋转矩形的代码

var s:UIComponent = new UIComponent();    
s.graphics.lineStyle(1, 0x0000FF);
s.graphics.drawRect(50, 50, 200, 200);
s.rotation = 30;
template.addChild(s);
其中,
模板
是画布。它的旋转很好,但问题是位置不正确。i、 e.旋转后不在(50,50)内。我怎样才能解决这个问题


提前谢谢

您看到的是Flex中围绕原点的默认旋转(在您的例子中,X,Y坐标为50,50),我假设您希望围绕中心旋转(就像我最近不得不做的那样)。有一种方法可以做到这一点,即根据旋转角度调整原点。然后是旋转效果:

import mx.effects.Rotate;

var s:UIComponent = new UIComponent();    
var rotator:Rotate = new Rotate(s);

s.graphics.lineStyle(1, 0x0000FF);
s.graphics.drawRect(50, 50, 200, 200);

rotator.angleFrom = 0;
rotator.angleTo = 30;
rotator.originX = s.width/2;
rotator.originY = s.height/2;
template.addChild(s);
rotator.play();
现在我注意到了一些问题,这需要我在play()方法之后再次设置旋转对象的宽度和高度,但除此之外,我得到了理想的旋转情况

另一个缺点是它是一种效果,这意味着它在视觉上旋转对象。如果您不想看到对象旋转,我将在更正后发回

答案是持续时间
只需在播放前添加
rotator.duration=1
,播放速度非常快,用户看不到。1等于1毫秒。我尝试了0,但结果没有发生旋转。显然,如果您想看到实际效果,可以使用任何毫秒值来增加时间长度。

接受一些答案。单击每个问题最佳答案旁边的绿色勾号。