0

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

1 に答える 1

1

試す

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