【问题标题】:Flex mxml to as3, small class did i miss something?Flex mxml to as3,小班我错过了什么吗?
【发布时间】:2008-11-26 13:14:26
【问题描述】:

我使用的是 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 { 导入 com.degrafa.geometry.RegularRectangle; 导入 com.degrafa.paint.SolidFill; 进口 com.degrafa.paint.SolidStroke; 导入 com.degrafa.GeometryGroup; 导入 com.degrafa.Surface; 导入 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 容器在那里,我可以看到跟踪拖动工作,但不再是矩形。

我错过了什么明显的东西吗? 谢谢

【问题讨论】:

    标签: apache-flex mxml degrafa


    【解决方案1】:

    尝试使用 BindingUtils 类设置绑定。

    例如:

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

    【讨论】:

      【解决方案2】:

      我想我找到了问题所在。 之前在mxml版本中我们有

      宽度=“{宽度}” 高度="{高度}"

      degrafa 矩形会自动适应其父级。

      但在 AS 版本中没有。我应该尝试在 As 中重现 {width} 和 {height}。 有什么工具可以将mxml转成as吗?

      【讨论】:

      • 解决方案!导入 mx.binding.utils.BindingUtils; BindingUtils.bindProperty(rect,"height",this,"height"); BindingUtils.bindProperty(rect,"width",this,"width");
      【解决方案3】:

      您是否为您的 RectangleShape 添加了Child?

      【讨论】:

        猜你喜欢
        • 2015-06-26
        • 2011-03-25
        • 1970-01-01
        • 1970-01-01
        • 2017-05-15
        • 2017-10-25
        • 1970-01-01
        • 2011-04-28
        • 1970-01-01
        相关资源
        最近更新 更多