2008-11-26 84 views
0

我使用的是mxml类,但由于我需要在构造时传递一些属性,为了使它更容易,我将它转换为as3代码。将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; 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容器是存在的,我能看到的轨迹拖动工作,但不是长方形了。

我错过了任何明显的东西? 谢谢

回答

3

尝试设置与BindingUtils类的绑定。

例如:

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

我想我指出了这个问题。 在MXML版本之前,我们有

宽度= “{}宽” 高度= “{height}的”

而且degrafa矩形将自动适应它的父。

但不在AS版本。我应该尝试在As中重现{width}和{height}。 任何工具将mxml转换为?

+0

解决方案! import mx.binding.utils.BindingUtils; BindingUtils.bindProperty(rect,“height”,this,“height”); BindingUtils.bindProperty(rect,“width”,this,“width”); – coulix 2008-11-26 14:16:04

0

你有没有你的addChild RectangleShape?

相关问题