【发布时间】: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