Yor*_*iev 0 apache-flex mxml initialization properties actionscript-3
我试图覆盖一个Button类,我有一些属性,我希望直接用组件的mxml描述初始化,如:
<sl:TMyButton id="btnX" x="168" y="223" width="290" label="Button" myproperty1="10" myproperty2="101" myproperty3="4"/>
Run Code Online (Sandbox Code Playgroud)
当具有mxml描述的所有属性都使用其值完全初始化时,哪个函数被触发(为了覆盖它)?
Flex组件在protected
命名空间中有4个方法,应该重写它们以解决不同的任务:
createChildren()
- 调用一次来创建和添加子组件.measure()
在布局过程中调用以计算组件大小.updateDisplayList()
将实际组件未缩放的宽度和高度作为参数.很明显,这种方法便于儿童定位.commitProperties()
是我建议您覆盖的方法,以便应用不需要应用组件大小的属性值.所以在你的情况下它可以是updateDisplayList()
或commitProperties()
.我建议你使用以下代码片段:
private var myproperty1Dirty:Boolean;
private var _myproperty1:String;
public function set myproperty1(value:String):void
{
if (_myproperty1 == value)
return;
_myproperty1 = value;
myproperty1Dirty = true;
// Postponed cumulative call of updateDisplayList() to place elements
invalidateDisplayList();
}
private var myproperty2Dirty:Boolean;
private var _myproperty2:String;
public function set myproperty2(value:String):void
{
if (_myproperty2 == value)
return;
_myproperty2 = value;
myproperty2Dirty = true;
// Postponed cumulative call of commitProperties() to apply property value
invalidatePropertues();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (myproperty1Dirty)
{
// Perform children placing which depends on myproperty1 changes
myproperty1Dirty = false;
}
}
override protected function commitProperties():void
{
super.commitProperties();
if (myproperty2Dirty)
{
// Apply changes of myproperty2
myproperty2Dirty = false;
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
归档时间: |
|
查看次数: |
182 次 |
最近记录: |