Flex mxml ad as3, piccola classe mi sono perso qualcosa?
-
11-07-2019 - |
Domanda
Stavo usando una classe mxml ma dato che ho bisogno di passare alcune proprietà in fase di costruzione, per rendere più semplice la convertirò in codice as3.
La classe è RectangleShape e disegna semplicemente un rettangolo.
Funzionamento mxml originale
<?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>
Il mio tentativo di AS3
pacchetto 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;
}
}
}
Il problema è che la forma non disegna più, il contenitore BaseShape è lì e posso vedere il trascinamento della traccia funzionante ma non più il rettangolo.
Qualche cosa ovvia che ho perso? Grazie
Soluzione
Prova a impostare i binding con la classe BindingUtils.
Ad esempio:
BindingUtils.bindProperty(component, "height", this, "height");
Altri suggerimenti
Penso di aver individuato il problema. Prima nella versione mxml avevamo
width = " {width} " altezza = " {altezza} "
E il rettangolo degrafa si adatterà automaticamente al suo genitore.
Ma non nella versione AS. dovrei provare a riprodurre {width} e {height} in As. Qualsiasi strumento per convertire mxml in come?
Hai aggiuntoChild your RectangleShape?