【问题标题】:Coordinates don't change dragging scaled fxg graphics坐标不会改变拖动缩放的 fxg 图形
【发布时间】:2013-02-24 18:15:33
【问题描述】:

我正在使用 FlashDevelop、actionscript 3 和 fxg 图形构建与 Illustrator(导出为 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);
        } 
    }
}

【问题讨论】:

  • 你不能缩放拖动的项目吗?我的意思是不要对拖动的项目应用转换,而是有一个将被拖动的容器和将应用转换的内容。你可以追踪更多吗(e.target);在 onMouseDown 和 onMouseUp 中?也许你拖的不是你认为拖的东西:):):)
  • 是的,也许我可以使用非缩放项目,但是当我发现问题时,我会尝试解决它。感谢您评论我的问题。

标签: actionscript-3 scale flashdevelop fxg


【解决方案1】:

试试

public var fxgRect:Sprite = new Sprite();
fxgRect.addChild(new fxgrectangle());

【讨论】:

  • 是的,它有效!!!伟大的!知道它为什么以这种方式工作会很有趣。它似乎与我的非常相似。无论如何,非常感谢。
  • 我会投票赞成你的答案,但我的声誉太低,我不能...... :)
  • '太棒了!知道它为什么以这种方式工作会很有趣'将问题块封装到movieclip中是非常古老的解决方法,我使用它和模拟收据sinse Flash 4 :)
  • 您需要使用这类技巧来处理在宽度、高度和比例上没有好的设置器和获取器的对象。主要问题是这些函数不影响对象的变换矩阵。有时它很好(当你想让文本字段更大时,你设置更大的宽度并且你对比例变化没有问题)但有时不是(就像你的情况一样)。解决方案是将该类型对象添加为其他(和变换父级)的子级或使用 transformation.matrix 修改(然后记住在修改后重新应用矩阵!)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-24
  • 1970-01-01
相关资源
最近更新 更多