【问题标题】:Flex binding and AS3Flex 绑定和 AS3
【发布时间】:2008-11-27 17:31:59
【问题描述】:

我在画布容器中有一个 degrafa 表面。 我想链接宽度和高度。 当我像预期一样使用绑定时:

// binding
   BindingUtils.bindProperty(rect,"height",this,"height"); 
   BindingUtils.bindProperty(rect,"width",this,"width"); 

现在,有人告诉我应该在 validateSize() 或 updateDisplayList() 上执行此操作, 以我目前对 flex 的了解,我真的不知道为什么,但我尝试了以下方法

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

    trace(unscaledWidth, unscaledHeight);
    this.width = unscaledWidth;
    rect.width =unscaledWidth;
    this.height = unscaledHeight;
    rect.height = unscaledHeight;

}

degrafa 矩形可以很好地调整大小,但不能很好地调整“this”画布容器。 他们似乎没有绑定,我错过了什么吗?

我还想稍微修改一下 rect.width = this.width 中的关系,其中包含一些我无法使用 bindproperty 方法完成的因素。

非常感谢任何线索。

【问题讨论】:

标签: apache-flex binding degrafa


【解决方案1】:

您应该调用 updateDisplayList 中的某处:

super.updateDisplayList(unscaledWidth, unscaledHeight); 

【讨论】:

    【解决方案2】:

    以防万一,

    更多代码

    public class RectangleShape extends BaseShape 
    {
    public function RectangleShape(fillColor:int) {
        super.name = shapeName;
        solidFill.color = fillColor;
    
    
        // shape
        solidFill.alpha = 0.3;
        rect.fill = solidFill;
        rect.stroke = solidStroke;    
        geoGroup.geometryCollection.addItem(rect);     
        geoGroup.target = surface;
    
        surface.graphicsCollection.addItem(geoGroup);  
        this.addChild(surface);
    
      // binding
      // BindingUtils.bindProperty(rect,"height",this,"height"); 
      // BindingUtils.bindProperty(rect,"width",this,"width"); 
    }
    
    
    
    
     override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
    
        trace(unscaledWidth, unscaledHeight);
        this.width = unscaledWidth;
        rect.width =unscaledWidth;
        this.height = unscaledHeight;
        rect.height = unscaledHeight;
    
    }
    

    【讨论】:

      【解决方案3】:

      updateDisplayList() 方法是您应该调整和定位组件子对象的位置。您不应该设置组件本身的大小(即:不要这样做:this.width=100)。

      您还可以在updateDisplayList() 中使用 Flash 图形 API 进行编程绘图。

      updateDisplayList() 由 Flex 调用,unscaledWidthunscaledHeight 两个参数是渲染组件的大小。您应该尊重这些尺寸,并根据它们设置组件的子对象的大小。

      updateDisplayList() 中设置大小时,不要直接修改宽度/高度属性。这样做会触发更多的 Flex 生命周期方法来执行。而是使用子组件的setActualSize() 方法。

      设置子对象的 x/y 属性也是如此。不要直接设置,使用move()方法。

      最后,在 Flex 4 中,他们为 Spark 组件添加了一些类似的生命周期方法。尽可能使用它们:setLayoutBoundsSize()setLayoutBoundsPosition()

      这是你原来的updateDisplayList(),按照上面的修改:

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
      
          trace(unscaledWidth, unscaledHeight);
      
          // like Janroel said above, you should call the super class method
          // the only time you don't need to is when your component extends UIComponent
          // (because UIComponent's updateDisplayList doesn't do anything)
          super.updateDisplayList(unscaledWidth, unscaledHeight);
      
          // don't do this (your component will get sized by its parent)
          //this.width = unscaledWidth;
          // if 'rect' inherits from UIComponent you should use the setActualSize() method:
          rect.setActualSize(unscaledWidth, unscaledHeight);
          // if it doesn't inherit from UIComponent, do it the regular way...
          rect.width =unscaledWidth;
          //this.height = unscaledHeight;
          rect.height = unscaledHeight;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-02
        • 1970-01-01
        相关资源
        最近更新 更多