本文介绍了坐标不改变拖拉缩放的FXG图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是FlashDevelop,动作3和FXG图形的建立与插图(导出为FXG 2.0)。

我导入FXG矩形建立与Illustrator中,那么当你短声就可以了,所以它的坐标改变我将它拖动。这适用于矩形比例为1(这意味着:无标度)。但是,如果我改变其规模(前fxgRect.scaleX = fxgRect.scaleY = 0.5。)你可以拖动它,但它的坐标不会改变!这让我疯了,因为精灵改变位置,但如果你问它的坐标,他们都没有变!我将 fxgRect.mouseChildren = FALSE; ,所以我一定要移动精灵fxgRect,而不是里面的东西吧。(这只是一个例子,我的目的是要建立复杂的图形使用Illustrator和使用它的FlashDevelop)。

感谢您提前帮助我。

这是在code做测试这个问题。要使用这个例子中,你必须创建一个FXG矩形(fxgrectangle.fxg),并把它放在SimpleDragFxg.as类的同一个文件夹。

 进口flash.display使用*。
进口flash.events *。
进口fxgrectangle;

公共类SimpleDragFxg扩展Sprite
{
    公共变种fxgRect:雪碧=新fxgrectangle(); //使fxgRect的istance

    公共职能SimpleDragFxg()
    {
        // ------------------------------------------------ ----------
        的addChild(fxgRect);
        fxgRect.name =FXGrect;
        fxgRect.x = fxgRect.y = 50;
        fxgRect.mouseChildren = FALSE;
        fxgRect.scaleX = fxgRect.scaleY = 0.5; //<<<这使得问题
        跟踪(我,this.name,我和遏制,this.fxgRect.name,其中包括fxgRect.getChildAt(0)。名称);
        fxgRect.addEventListener(的MouseEvent.MOUSE_DOWN,onmousedown事件);
        // ------------------------------------------------ --------------
    }
    私有函数onmousedown事件(E:MouseEvent)方法:无效
    {
        跟踪(e.target:e.target.name);
        如果项(DisplayObject(e.target)。名称==FXGrect)
        {
            跟踪(以前拖FXGrect位置:fxgRect.x,fxgRect.y);
            雪碧(e.target).startDrag();
            stage.addEventListener(侦听MouseEvent.MOUSE_UP,onMouseUp);
        }
    }
    私有函数onMouseUp(E:MouseEvent)方法:无效
    {
        fxgRect.stopDrag();
        stage.removeEventListener(侦听MouseEvent.MOUSE_UP,onMouseUp);
        如果项(DisplayObject(e.target)。名称==FXGrect)
        {
            跟踪(拖后FXGrect位置:fxgRect.x,fxgRect.y);
        }
    }
}
 

解决方案

尝试

 公共变种fxgRect:雪碧=新的Sprite();
fxgRect.addChild(新fxgrectangle());
 

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);
        } 
    }
}
解决方案

Try

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

这篇关于坐标不改变拖拉缩放的FXG图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 20:19