Coordinates don't change dragging scaled fxg graphics

非 Y 不嫁゛ 提交于 2019-12-10 12:23:51

问题


I'm using FlashDevelop, actionscript 3 and fxg graphics build with Illustrator (exported as fxg 2.0).

I import a fxg rectangle build with Illustrator, then I set it draggable when you clik on it, so its coordinates change. This works if the rectangle scale is 1 (this means: no scale). But, if I change its scale (ex. fxgRect.scaleX = fxgRect.scaleY = 0.5; ) you can drag it but its coordinates doesn't change!! And this make me crazy because the sprite changes position but if you ask its coordinates they aren't changed!! And I set the fxgRect.mouseChildren = false; so I'm sure to move the sprite fxgRect and not something inside it. (This is just an example, my aim is to build complex graphics with illustrator and use it in FlashDevelop).

Thank you in advance for help me.

This is the code done to test this problem. To use this example you have to create a fxg rectangle (fxgrectangle.fxg) and put it in the same folder of the SimpleDragFxg.as class.

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);
        } 
    }
}

回答1:


Try

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


来源:https://stackoverflow.com/questions/15054891/coordinates-dont-change-dragging-scaled-fxg-graphics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!