我有一个组大小到它包含的内容但是要使用Tweener执行转换我必须设置width和height属性。动画完成后,如何清除显式宽度和高度属性,以便组根据其内容返回大小调整?
之前:
<s:Group ><content.../></s:Group>
代码:
width = 250;
height = 250;
Tweener.addTween(this, {width:500, height:500, time:0.25, onComplete:openAnimationComplete});
在补间之后,有效地将组设置为500x500,就像这样:
<s:Group width="500" height="500" ><content /></s:Group>
我希望它回到这个:
<s:Group ><content /></s:Group>
更新
使用Flextras的解决方案测试代码:
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
var w:Object = myGroup.width;
var h:Object = myGroup.height;
if (myGroup.width!=300) {
myGroup.width = 300;
myGroup.height = 300;
}
else {
myGroup.width = NaN;
myGroup.height = NaN;
w = myGroup.width; // NaN
h = myGroup.height; // NaN
//myGroup.validateNow()
if (myGroup.parent is IInvalidating) {
IInvalidating(myGroup.parent).validateNow();
}
w = myGroup.width; // 600
h = myGroup.height; // 100
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Group id="myGroup" minHeight="0" minWidth="0" clipAndEnableScrolling="true">
<s:Button width="600" height="100" label="here is a button" click="button1_clickHandler(event)"/>
</s:Group>
答案 0 :(得分:3)
将高度和宽度设置为NaN;这将有效地告诉Flex框架“我不知道这个值是什么”,然后在下一次组件渲染时执行measure()事件;导致它更新measuredHeight和measuredWidth属性;然后,父容器将使用它来调整组的大小。