Frage

ich eine MXML-Klasse wurde mit aber da ich einige Eigenschaften bei Bauzeit übergeben müssen, ist es einfacher machen ich es AS3-Code konvertiert.

Die Klasse ist RectangleShape und es zieht nur ein Rechteck.

Original mxml Arbeits

<?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>

Mein Versuch, AS3

Paket org.edorado.edoboard.view.components.shapes {     import com.degrafa.geometry.RegularRectangle;     import com.degrafa.paint.SolidFill;     import com.degrafa.paint.SolidStroke;     import com.degrafa.GeometryGroup;     import com.degrafa.Surface;     Import 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;
    }
}

}

Das Problem ist, dass die Form nicht mehr zieht, der Baseshape Behälter ist, und ich kann die Spur ziehen arbeiten, aber nicht das Rechteck mehr sehen.

Jede offensichtliche Sachen, die ich verpasst? Dank

War es hilfreich?

Lösung

Versuchen Sie, die Bindungen mit der BindingUtils Klasse einrichten.

Zum Beispiel:

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

Andere Tipps

Ich glaube, ich das Problem aufgezeigt. Bevor in der MXML-Version hatten wir

width = "{width}" height = "{height}"

Und das degrafa Rechteck wird automatisch seine Eltern passen.

Aber nicht in der AS-Version. ich sollte versuchen, die {width} und {height} in As zu reproduzieren. Jedes Tool konvertiert mxml als?

Haben Sie AddChild Ihre RectangleShape?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top