Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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
Apache flex 是否可以使用Flex旋转动态添加的线?_Apache Flex - Fatal编程技术网

Apache flex 是否可以使用Flex旋转动态添加的线?

Apache flex 是否可以使用Flex旋转动态添加的线?,apache-flex,Apache Flex,我正在使用canvas.moveTo(0,0)向画布添加一行;canvas.lineTo(100100),但我希望用户移动鼠标以设置线的旋转。谷歌建议使用rotation属性,但我没有对line对象的引用。我可以得到一个参考线,还是应该旋转整个画布?这有可能吗?嗯。。。将精灵添加到画布,然后在精灵的图形对象上绘制线条。然后你可以旋转精灵等。如果你想旋转画布,你可以旋转画布,但是如果你只想将画布视为精灵,那么创建画布会增加额外的开销(请注意,画布将精灵延伸到链的某个地方) 从ASDocs中看一看这

我正在使用
canvas.moveTo(0,0)向画布添加一行;canvas.lineTo(100100),但我希望用户移动鼠标以设置线的旋转。谷歌建议使用
rotation
属性,但我没有对line对象的引用。我可以得到一个参考线,还是应该旋转整个画布?这有可能吗?

嗯。。。将精灵添加到画布,然后在精灵的图形对象上绘制线条。然后你可以旋转精灵等。如果你想旋转画布,你可以旋转画布,但是如果你只想将画布视为精灵,那么创建画布会增加额外的开销(请注意,画布将精灵延伸到链的某个地方)


从ASDocs中看一看这个示例:

通常,您可以操纵图形绘制到的曲面——通常是一个Sprite实例,因为它非常轻量级,非常适合该任务。相反,如果您创建了一个新的精灵,使用它的图形对象绘制线条、形状等,将精灵添加到UIComponent中--您不能直接将精灵添加到画布中,而不先将其包装到UIComponent实例中--然后将该UIComponent添加到画布中,您可以通过旋转、移动直接操纵精灵,等等

这通常是通过重写createChildren()(如果对象打算在组件实例的持续时间内存在)或使用其他方法来完成的,具体取决于您的需要。例如:

override protected function createChildren():void
{
    super.createChildren();

    // Create a new Sprite and draw onto it
    var s:Sprite = new Sprite();
    s.graphics.beginFill(0, 1);
    s.graphics.drawRect(0, 0, 20, 20);
    s.graphics.endFill();

    // Wrap the Sprite in a UIComponent
    var c:UIComponent = new UIComponent();
    c.addChild(s);

    // Rotate the Sprite (or UIComponent, whichever your preference)
    s.rotation = 45;

    // Add the containing component to the display list
    this.addChild(c);
}
希望有帮助

什么是画布(实际的画布没有lineTo()或moveTo()方法)

看起来您可能正在操纵画布的图形对象。在这种情况下,您最好执行以下操作

private var sp : Sprite;
//canvas is whatever Canvas you wish to add the sprite to
private function addLine(canvas : Canvas) : void {
sp = new Sprite();
/* Do the drawing of the sprite here,
   such as sp.graphics.moveTo or sp.graphics.lineTo */
sp.rotation = 45;
canvas.rawChildren.addChild(sp);
}
然后,每当您希望更改旋转时,只需更新sp.rotation(现在位于画布中)