English 中文(简体)
Flex MXML 转换为 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; 
            Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate.

            override public function updateFillColor(color:int):void {
                solidFill.color = color;
            Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate.

        ]]>
    </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 = "{solidFillSorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate."
                width="{widthSorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate." 
                height="{heightSorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate."
                stroke="{stroke1Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate." />
        </degrafa:GeometryGroup>        
    </degrafa:Surface>
</BaseShape>

我的 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); 
    Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate.

    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);
    Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate.

    override public function updateFillColor(color:int):void {
        solidFill.color = color;
    Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate.
Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate.

Sorry, there is no text provided for me to translate into Chinese. Please provide the text you want me to translate.

问题是形状不再绘制了,BaseShape容器在那里,我可以看到跟踪的拖动正在工作,但不再有矩形。

Any obvious stuff i missed ? Thanks

最佳回答

尝试使用BindingUtils类设置绑定。

例如:

BindingUtils.bindProperty(component, "height", this, "height"); 
问题回答

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

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

Degrafa矩形将自动适应其父级。

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

你添加了 RectangleShape 吗?





相关问题
热门标签