Question

J'utilisais une classe mxml, mais comme je dois transmettre certaines propriétés au moment de la construction, pour le rendre plus facile, je vais le convertir en code as3.

La classe est RectangleShape et dessine simplement un rectangle.

Le mxml original fonctionne

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

Ma tentative d'AS3

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

}

Le problème est que la forme ne dessine plus, le conteneur BaseShape est présent et je peux voir que le traçage de la trace fonctionne mais pas le rectangle.

Des choses évidentes que j'ai manquées? Merci

Était-ce utile?

La solution

Essayez de configurer les liaisons avec la classe BindingUtils.

Par exemple:

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

Autres conseils

Je pense avoir identifié le problème. Avant dans la version XML, nous avions

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

Et le rectangle degrafa s’adaptera automatiquement à son parent.

Mais pas dans la version AS. Je devrais essayer de reproduire les {width} et {height} en tant que. Un outil pour convertir le MXX en tant que?

Avez-vous ajoutéChild votre RectangleShape?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top