ChangeWatcher 用法 ---- import mx.binding.utils.ChangeWatcher;

本文介绍了一个Flex应用程序中属性绑定的具体实现案例。通过使用BindingUtils和ChangeWatcher等工具,演示了如何在不同组件间建立数据绑定,并提供了绑定和解除绑定的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现绑定

<?xml version="1.0" ?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"> 
<mx:Script> 
<![CDATA[ 
import mx.events.PropertyChangeEvent; 
     import mx.binding.utils.ChangeWatcher; 
     import mx.binding.utils.BindingUtils; 
     import mx.controls.Alert; 
       
       private var namewatcher:ChangeWatcher; 
       private function init():void 
       { 
            namewatcher = BindingUtils.bindProperty(personName,"text",person,"text"); 
            ChangeWatcher.watch(personName,"text",nameSetter);  
       } 
       
       private function bindMe():void{ 
            namewatcher = BindingUtils.bindProperty(txt,"text", txtInp,"text");//前面属性跟着后面属性变化 
       } 
       
       private function unbindMe():void{ 
            namewatcher.unwatch();            
       } 
       private function nameSetter(event:Event):void 
       { 
               Alert.show(personName.text); 
       } 

]]> 
</mx:Script> 
    <mx:Panel width="514" height="200" layout="absolute">
        <mx:Label text="txtInp" width="51" x="20" y="10"/>
        <mx:Label text="txt" width="51" x="20" y="38"/>
        <mx:TextInput id="txtInp" width="200"  x="94" y="8"/>
        <mx:Text id="txt" width="200"  x="94" y="38"/>
        <mx:Button label="Bind TextInput to Text" click="bindMe()"  x="83" y="128"/>
        <mx:Button label="Unbind TextInput to Text" click="unbindMe()"  x="260" y="128"/>
        <mx:TextInput id="personName" x="94" y="80" width="126"/>
        <mx:TextInput id="person" x="299" y="80"/>
        <mx:Label text="personName" width="80" x="0" y="82"/>
        <mx:Label text="person" width="49" x="228" y="82"/>
    </mx:Panel>
</mx:Application>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值