0

我正在使用 FlashDevelop、actionscript 3 和使用 Illustrator 构建的 fxg 图形(导出为 fxg 2.0)。

我用 Illustrator 导入了一个 fxg 矩形构建,然后当你点击它时我将它设置为可拖动的,所以它的坐标会改变。如果矩形比例为 1(这意味着:无比例),则此方法有效。但是,如果我改变它的比例(例如 fxgRect.scaleX = fxgRect.scaleY = 0.5; )你可以拖动它但它的坐标不会改变!!这让我抓狂,因为精灵改变了位置,但如果你问它的坐标,它们并没有改变!我设置了,fxgRect.mouseChildren = false;所以我确定要移动精灵 fxgRect 而不是它里面的东西。(这只是一个例子,我的目标是用 illustrator 构建复杂的图形并在 FlashDevelop 中使用它)。

预先感谢您对我的帮助。

这是为测试此问题而编写的代码。要使用此示例,您必须创建一个 fxg 矩形 (fxgrectangle.fxg) 并将其放在 SimpleDragFxg.as 类的同一文件夹中。

import flash.display.*;
import flash.events.*;
import fxgrectangle;

public class SimpleDragFxg extends Sprite
{
    public var fxgRect:Sprite = new fxgrectangle(); // make an istance of fxgRect

    public function SimpleDragFxg()
    {
        //----------------------------------------------------------
        addChild(fxgRect);
        fxgRect.name = "FXGrect";
        fxgRect.x = fxgRect.y = 50;
        fxgRect.mouseChildren = false;
        fxgRect.scaleX = fxgRect.scaleY = 0.5; //<<< this makes the problem
        trace ("I'm ", this.name, "and I contain ", this.fxgRect.name, "which contains ", fxgRect.getChildAt(0).name);
        fxgRect.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
        //--------------------------------------------------------------
    }
    private function onMouseDown (e:MouseEvent):void
    {
        trace ("e.target: ", e.target.name);
        if (DisplayObject(e.target).name == "FXGrect")
        {
            trace ("FXGrect position BEFORE drag: ", fxgRect.x, fxgRect.y);
            Sprite(e.target).startDrag();
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        }
    }
    private function onMouseUp (e:MouseEvent):void
    {
        fxgRect.stopDrag();
        stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        if (DisplayObject(e.target).name == "FXGrect")
        {
            trace ("FXGrect position AFTER drag: ", fxgRect.x, fxgRect.y);
        } 
    }
}
4

1 回答 1

1

尝试

public var fxgRect:Sprite = new Sprite();
fxgRect.addChild(new fxgrectangle());
于 2013-02-25T15:11:44.880 回答