此實現不是綁定的 - 如果FOO()的變化的結果,它不會對你的反映顯示列表。
雖然,我想這應該在創建完整的工作,一旦:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600">
<fx:Script>
<![CDATA[
private function foo():Boolean
{
return false;
}
]]>
</fx:Script>
<s:Button label="text"
visible="{foo()}" />
</s:Application>
一個更好的辦法是結合演示模型,利用綁定,在這裏看到:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
[Bindable]
public var presentationVisible:Boolean = true;
private var timer:Timer = new Timer(500);
private function foo():void
{
presentationVisible = Math.random() > 0.5 ? true : false;
}
protected function creationCompleteHandler(event:FlexEvent):void
{
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
protected function timerHandler(event:TimerEvent):void
{
foo();
}
]]>
</fx:Script>
<s:Button label="text"
visible="{presentationVisible}" />
</s:Application>
您是否試圖在綁定中使用閉包來執行此操作? –
我不知道我很明白你在問什麼 – randomUser56789