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);
        } 
    }
}
AntonioG
  • 1
  • 1
  • Can you DO NOT scale dragged item? I mean do not apply transformation on the dragged item instead have a container which will be dragged and content that will have transformation applied. More over can you trace(e.target); in the onMouseDown and onMouseUp? Maybe you dragging not what you think you drag:):):) – Lukasz 'Severiaan' Grela Feb 25 '13 at 07:46
  • Yes, maybe I could use non scaled items, but when I find a problem I try to solve it. Thank you to comment my question. – AntonioG Feb 27 '13 at 21:17

1 Answers1

1

Try

public var fxgRect:Sprite = new Sprite();
fxgRect.addChild(new fxgrectangle());
Smolniy
  • 456
  • 3
  • 9
  • Yes, it works!!! Great! It would be interesting to know why it works in this way. It seems to be very similar to mine. Anyway, thank you very much. – AntonioG Feb 27 '13 at 21:07
  • I'd vote up your answer but my reputation is too low and I can't... :) – AntonioG Feb 27 '13 at 21:25
  • 'Great! It would be interesting to know why it works in this way' It's very old workaround to encapsulate problem block into movieclip, i use it and simular receipts sinse Flash 4 :) – Smolniy Feb 28 '13 at 06:49
  • You need to do that type of tricks to work with object that don't have good setters and getters on width, height and scale. Mainly problem is that those functions don't affect transformation matrix of object. Sometimes its good (when you want to make textfield larger you set larger width and you don't have problem with scale change) but somtimes not (like your case). The solution is to add that type objects as children of other (and transform parent) or use transformation.matrix modifications (then remember to reapply matrix after modifications!). – Konrad Apr 19 '13 at 12:01