Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 围绕中心旋转flex图形对象_Actionscript 3_Apache Flex_Graphics_Rotation - Fatal编程技术网

Actionscript 3 围绕中心旋转flex图形对象

Actionscript 3 围绕中心旋转flex图形对象,actionscript-3,apache-flex,graphics,rotation,Actionscript 3,Apache Flex,Graphics,Rotation,我试图创建一个圆弧的旋转动画。即使尝试了所有这些示例,我也无法围绕中心旋转它。它正在围绕左上角旋转 private function init():void { var hgroup:Group=new Group(); this.addElement(hgroup); arc1=new Graphic(); arc1.graphics.lineStyle(12,0xff0000,1

我试图创建一个圆弧的旋转动画。即使尝试了所有这些示例,我也无法围绕中心旋转它。它正在围绕左上角旋转

private function init():void
        {
            var hgroup:Group=new Group();
            this.addElement(hgroup);

            arc1=new Graphic();
            arc1.graphics.lineStyle(12,0xff0000,1,false,"normal",CapsStyle.SQUARE);
            draw_arc(arc1,CENTER,CENTER,70,14,288,1);

            hgroup.addElement(arc1);

            var matrix:Matrix = arc1.transform.matrix; 
            var rect:Rectangle = arc1.getBounds(arc1.parent); 
            matrix.translate(- (rect.left + (rect.width/2)), - (rect.top + (rect.height/2))); 
            matrix.rotate((90/180)*Math.PI); 
            matrix.translate(rect.left + (rect.width/2), rect.top + (rect.height/2));

            var rot:Rotate = new Rotate();
            rot.angleBy = 360;
            rot.duration = 1000;
            rot.target = arc1;
            rot.play();

        }

        public function draw_arc(movieclip:Sprite,center_x:Number,center_y:Number,radius:Number,angle_from:Number,angle_to:Number,precision:Number):void {
            var angle_diff:Number=angle_to-angle_from;
            var steps:Number=Math.round(angle_diff*precision);
            var angle:Number=angle_from;
            var px:Number=center_x+radius*Math.cos(angle*deg_to_rad);
            var py:Number=center_y+radius*Math.sin(angle*deg_to_rad);
            movieclip.graphics.moveTo(px,py);
            for (var i:Number=1; i<=steps; i++) {
                angle=angle_from+angle_diff/steps*i;
                movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
            }
        }
private function init():void
{
var hgroup:Group=新组();
本.addElement(hgroup);
arc1=新图形();
arc1.图形.线型(12,0xff0000,1,假,“正常”,CapssStyle.方形);
画弧(弧1,中心,中心,70,14288,1);
hgroup.addElement(arc1);
var矩阵:矩阵=arc1.transform.matrix;
var rect:Rectangle=arc1.getBounds(arc1.parent);
矩阵平移(-(rect.left+(rect.width/2)),-(rect.top+(rect.height/2));
矩阵旋转((90/180)*数学PI);
translate(rect.left+(rect.width/2)、rect.top+(rect.height/2));
变量rot:Rotate=newrotate();
rot.angleBy=360;
rot.duration=1000;
rot.target=arc1;
腐烂。玩耍();
}
公共函数绘制弧(movieclip:Sprite,center\u x:Number,center\u y:Number,radius:Number,angle\u from:Number,angle\u to:Number,precision:Number):无效{
var angle\u diff:Number=角度到角度的距离;
变量步数:数字=数学圆(角度差*精度);
变量角度:数字=角度;
变量px:数值=中心x+半径*数学cos(角度*度到弧度);
变量py:数字=中心y+半径*数学sin(角度*度到弧度);
movieclip.graphics.moveTo(px,py);
对于(var i:Number=1;i我有一个类似的问题(带有一个旋转箭头),我这样修复它:

<s:Group width="0" height="0" verticalCenter="0" right="14">
    <s:Graphic id="arrow" rotation="90" rotation.selectedStates="0">
        <s:Path data="M 0 0 L 5 5 L 0 10 Z" left="-2.5" top="-5">
            <s:fill>
                <s:SolidColor id="arrowFill"/>
            </s:fill>
        </s:Path>
    </s:Graphic>
</s:Group>

容器
的大小设置为
0
,因为它只作为所包含图形的定位点。此
的位置是旋转中心点。
图形
中的
路径
的定位使其定位点位于其中心(也就是说,它的宽度为5px,高度为10px,因此它被重新定位为左侧2.5px,顶部5px)


实际旋转是通过此处的
状态
变换
完成的,但是
效果
做的是相同的事情。

您需要此属性:

rot.autoCenterTransform="true"

请参阅文档底部的示例:

我以前使用过此解决方案;它运行良好,非常简单:


要在中心旋转图像,必须指定此属性

rot.autoCenterTransform="true";
rot.applyChangesPostLayout = false;