首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flex mxml到as3,小类我错过了什么吗?

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

Stack Overflow用户
提问于 2008-11-26 13:14:26
回答 3查看 1.5K关注 0票数 0

我使用的是一个mxml类,但是由于我需要在构建时传递一些属性,为了使它更容易,我将把它转换为as3代码。

类是RectangleShape,它只绘制一个矩形。

原始mxml工作

代码语言:javascript
复制
<?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;

代码语言:javascript
复制
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容器在那里,我可以看到跟踪拖动工作,但不再是矩形。

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2008-11-26 19:16:03

尝试使用BindingUtils类设置绑定。

例如:

代码语言:javascript
复制
BindingUtils.bindProperty(component, "height", this, "height"); 
票数 3
EN

Stack Overflow用户

发布于 2008-11-26 14:08:16

我想我找出了问题所在。在之前的mxml版本中

Width=“{宽度}”height="{height}“

退化矩形将自动适合它的父方。

但不是在AS版本中。我应该尝试在As中复制{width}和{height}。有什么工具可以将mxml转换成as?

票数 0
EN

Stack Overflow用户

发布于 2009-05-26 15:25:00

你addChild你的RectangleShape吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/320659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档