我使用的是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 { 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;
}
}
}
问题是形状不再绘制了,BaseShape容器就在那里,我可以看到跟踪拖动工作了但不再是矩形了。
我错过了哪些明显的东西? 感谢
答案 0 :(得分:3)
尝试使用BindingUtils类设置绑定。
例如:
BindingUtils.bindProperty(component, "height", this, "height");
答案 1 :(得分:0)
我想我确定了这个问题。 之前我们有mxml版本
宽度= “{}宽度” 高度= “{}高度”
并且degrafa矩形将自动适合其父级。
但不是AS版本。我应该尝试在As中重现{width}和{height}。 是否有将mxml转换为?
的工具答案 2 :(得分:0)
你是否添加了你的RectangleShape?