Flex 绑定和 AS3

发布于 2024-07-08 21:29:01 字数 787 浏览 11 评论 0原文

我将 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 矩形的大小调整得很好,但不是“这个”画布容器。 他们似乎没有绑定,我错过了什么吗?

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

非常感谢您提供任何线索。

I have a degrafa surface into a canvas container.
I want to link both width and height.
When i use binding like it works as expected:

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

Now, someone told me that i should do it on validateSize() or updateDisplayList(),
with my current knowledge of flex i dont realy know why but i tried the following

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

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

}

The degrafa rectangle get resized well but not the 'this' canvas container.
They seem to be not binded, did i miss something ?

Also i would like to modify a little bit the relation in rect.width = this.width with some factor in it which i cant do using the bindproperty method.

Thanks a lot for any clue.

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

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

发布评论

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

评论(3

半﹌身腐败 2024-07-15 21:29:01

您应该在 updateDisplayList 中的某个位置调用:

super.updateDisplayList(unscaledWidth, unscaledHeight); 

Somewhere in your updateDisplayList you should call:

super.updateDisplayList(unscaledWidth, unscaledHeight); 
爱情眠于流年 2024-07-15 21:29:01

以防万一,

还有一些代码

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;

}

Just in case,

some more code

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;

}
烛影斜 2024-07-15 21:29:01

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

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

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

The updateDisplayList() method is where you should size and position your component's child objects. You should not be setting the size of the component itself (ie: don't do: this.width=100).

You can also do programatic drawing in updateDisplayList(), using the Flash graphics apis.

updateDisplayList() is called by Flex and the two parameters unscaledWidth and unscaledHeight are the size that your component will be rendered at. You should honor those dimensions, and set the size of your component's child objects based on them.

When setting the size in updateDisplayList(), you do not modify the width/height properties directly. Doing this will trigger more Flex life cycle methods to execute. Instead, use the setActualSize() method of the child component.

The same things goes with setting the x/y properties of your child object. Don't set them directly, use the move() method.

Finally, in Flex 4 they added some analogous life cycle methods for Spark components. Use them where possible: setLayoutBoundsSize(), setLayoutBoundsPosition().

Here's your original updateDisplayList(), modified as per above:

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文