Flex mxml 到 as3,小班我错过了什么吗?

发布于 2024-07-10 12:05:19 字数 3198 浏览 8 评论 0原文

我使用的是 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 容器就在那里,我可以看到跟踪拖动正在工作,但不再是矩形了。

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

I was using an mxml class but since i need to pass some properties at construction time, to make it easier i will convert it to as3 code.

The class is RectangleShape and it just draws a rectangle.

Original mxml working

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

My attempt to AS3

package 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;
    }
}

}

The problem is that the shape is not drawing anymore, the BaseShape container is there and i can see the trace drag working but not the rectangle anymore.

Any obvious stuff i missed ?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光礼记 2024-07-17 12:05:20

我想我已经指出了问题所在。
之前在 mxml 版本中我们有

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

并且 degrafa 矩形将自动适合其父级。

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

I think i pinpointed the problem.
Before in the mxml version we had

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

And the degrafa rectangle will automatically fit its parent.

But not in the AS version. i should try to reproduce the {width} and {height} in As.
Any tool to convert mxml to as?

幻想少年梦 2024-07-17 12:05:20

您添加了 RectangleShape 的子项吗?

Did you addChild your RectangleShape?

垂暮老矣 2024-07-17 12:05:19

尝试使用 BindingUtils 类设置绑定。

例如:

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

Try setting up the bindings with the BindingUtils class.

For example:

BindingUtils.bindProperty(component, "height", this, "height"); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文