<?xml version="1.0"?>
<!-- events/SimpleEventHandler.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script><![CDATA[
import mx.controls.Alert;
[Bindable]
public var a:String = "test";
public var b:String;
private function myEventHandler2(event:MouseEvent):void {
// Do something with the MouseEvent object.
b = a;
a = "changed";
Alert.show("b is " + b +" a is " + a);
}
]]></mx:Script>
<mx:Button id="b2" label="Click Me " click="myEventHandler2(event)"/>
<mx:Label id="label2" text="{b}" />
</mx:Application>
會報錯:Data binding will not be able to detect assignments to "b".因爲在<mx:Label id="label2" text="{b}" />中綁定了b,所以要在public var b:String;前加上 [Bindable],且雖然 b = a,但a變了後b不會馬上變的。alert
"b is test a is changed"