Flex 绑定和 AS3
我将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在 updateDisplayList 中的某个位置调用:
Somewhere in your updateDisplayList you should call:
以防万一,
还有一些代码
Just in case,
some more code
updateDisplayList()
方法是您应该调整组件子对象的大小和位置的地方。 您不应该设置组件本身的大小(即:不要这样做:this.width=100
)。您还可以使用 Flash 图形 API 在
updateDisplayList()
中进行编程绘图。updateDisplayList()
由 Flex 调用,两个参数unscaledWidth
和unscaledHeight
是组件渲染时的尺寸。 您应该尊重这些尺寸,并根据它们设置组件的子对象的大小。在
updateDisplayList()
中设置大小时,不要直接修改宽度/高度属性。 这样做将触发更多 Flex 生命周期方法的执行。 相反,请使用子组件的setActualSize()
方法。设置子对象的 x/y 属性也是如此。 不要直接设置它们,请使用
move()
方法。最后,在 Flex 4 中,他们为 Spark 组件添加了一些类似的生命周期方法。 尽可能使用它们:
setLayoutBoundsSize()
、setLayoutBoundsPosition()
。这是您的原始
updateDisplayList()
,按上述修改: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 parametersunscaledWidth
andunscaledHeight
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 thesetActualSize()
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: