我使用MXML类但因为我需要通过在构造时的一些性质,以使其更易于我将其转换为AS3代码。

类是RectangleShape,它只是绘制一个矩形。

<强>原始MXML工作

<?xml version="1.0" encoding="utf-8"?>
<BaseShape name="rectangle"
    xmlns="org.edorado.edoboard.view.components.shapes.*" 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:degrafa="http://www.degrafa.com/2007"
    xmlns:objecthandles="com.roguedevelopment.objecthandles.*">

    <mx:Script>
        <![CDATA[

            import org.edorado.edoboard.view.components.shapes.IShape;
            import mx.events.FlexEvent;

            override public function drag(movePt:Point):void {
                this.width = movePt.x - this.x; 
                this.height = movePt.y - this.y; 
            }

            override public function updateFillColor(color:int):void {
                solidFill.color = color;
            }

        ]]>
    </mx:Script>

    <degrafa:Surface >
        <degrafa:GeometryGroup id="geo">
            <degrafa:fills>
                <degrafa:SolidFill id="solidFill" color="white" alpha="0.3"/>
            </degrafa:fills>

            <degrafa:strokes>
                <degrafa:SolidStroke id="stroke1" color="white"/>
            </degrafa:strokes>

            <degrafa:RegularRectangle 
                id="rect" 
                fill = "{solidFill}"
                width="{width}" 
                height="{height}"
                stroke="{stroke1}" />
        </degrafa:GeometryGroup>        
    </degrafa:Surface>
</BaseShape>

我试图AS3

包org.edorado.edoboard.view.components.shapes {     进口com.degrafa.geometry.RegularRectangle;     进口com.degrafa.paint.SolidFill;     进口com.degrafa.paint.SolidStroke;     进口com.degrafa.GeometryGroup;     进口com.degrafa.Surface;     进口flash.geom.Point;

public class RectangleShape extends BaseShape 
{
    public var surface:Surface = new Surface(); 
    public var geoGroup:GeometryGroup = new GeometryGroup();
    public var solidFill:SolidFill = new SolidFill("white");
    public var solidStroke:SolidStroke = new SolidStroke("black");
    public var rect:RegularRectangle = new RegularRectangle(); 

    public static const name:String = "rectangle";

    public function RectangleShape() {
        addChild(surface);
        //surface.addChild(geoGroup);
        surface.graphicsCollection.addItem(geoGroup); 

        solidFill.alpha = 0.3;
        rect.fill = solidFill;
        rect.stroke = solidStroke;
        rect.width = this.width;
        rect.height = this.height;
        geoGroup.geometry = [rect];
        geoGroup.draw(null, null); 
    }

    override public function drag(movePt:Point):void {

        this.width = movePt.x - this.x; 
        this.height = movePt.y - this.y; 
        trace('dragging ', this.width, this.height);
    }

    override public function updateFillColor(color:int):void {
        solidFill.color = color;
    }
}

}

的问题是,形状并不绘制了,该容器BaseShape是存在的,我可以看到的跟踪拖动工作,但不是矩形了。

任何明显的东西我错过? 感谢

有帮助吗?

解决方案

尝试用BindingUtils类建立绑定。

例如:

BindingUtils.bindProperty(component, "height", this, "height"); 

其他提示

我想我精确定位的问题。 之前在MXML版本中,我们有

宽度= “{}宽度” 高度= “{}高度”

和所述degrafa矩形将自动适应它的父。

,但不是在AS版本。我应该尝试重现中作为{宽度}和{高度}。 任何工具来MXML转换为?

你的addChild你RectangleShape?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top