关于binding的一个问题

来源:互联网 发布:搜狗 mac 快捷键 编辑:程序博客网 时间:2024/06/01 14:25

<?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"

原创粉丝点击