Flex mxml a as3, clase pequeña ¿Me perdí algo?
-
11-07-2019 - |
Pregunta
Estaba usando una clase mxml pero como necesito pasar algunas propiedades en el momento de la construcción, para que sea más fácil, la convertiré a código as3.
La clase es RectangleShape y solo dibuja un rectángulo.
Trabajo original de 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>
Mi intento de AS3
paquete 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; importar 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;
}
}
}
El problema es que la forma ya no se dibuja, el contenedor de BaseShape está ahí y puedo ver el arrastre de rastreo funcionando pero ya no el rectángulo.
¿Alguna cosa obvia que me perdí? Gracias
Solución
Intente configurar los enlaces con la clase BindingUtils.
Por ejemplo:
BindingUtils.bindProperty(component, "height", this, "height");
Otros consejos
Creo que identifiqué el problema. Antes en la versión mxml teníamos
ancho = " {ancho} " height = " {height} "
Y el rectángulo degrafa se ajustará automáticamente a su padre.
Pero no en la versión AS. Debería intentar reproducir el {ancho} y {alto} en As. ¿Alguna herramienta para convertir mxml a como?
¿AgregasteChild your RectangleShape?