欢迎来到代码驿站!

当前位置:首页 >

Flex 动态绑定BindingUtils.bindProperty

时间:2023-02-09 13:13:50|栏目:|点击:
关键字:BindingUtils.bindProperty
需导入:import mx.binding.utils.BindingUtils;
/**
* 动态绑定
* @params site:Object 被绑定对象
* @params prop:String 被绑定对象的属性,如textInput的text属性
* @params host:Object 监视者对象
* @params chain:Object 监视者对象的属性
* @return ChangeWatcher
* **/
BindingUtils.bindProperty(site:Object,prop:String,host:Object,chain:Object);
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" initialize="init();">

    <mx:Script>
        <!--[CDATA[
            import mx.binding.utils.BindingUtils;
            import mx.binding.utils.ChangeWatcher;

            
            private var watcher1:ChangeWatcher;
            private var watcher2:ChangeWatcher;

            /**
             * 动态绑定
             * @return void
             * **/
            private function Binding():void {

                //绑定ID为txt2的txtInput
                //绑定属性为txtInput的text
                //监视者ID为txt1的txtInput
                //监视者属性为txtInput的text
                watcher1 = BindingUtils.bindProperty(txt2,"text",txt1,"text");

                //绑定ID为txtComb的txtInput
                //绑定属性为txtInput的text
                //监视者ID为comb的ComboBox
                //监视者属性为ComboBox的value
                watcher2 = BindingUtils.bindProperty(txtComb,"text",comb,"value");
            }

            /**
             * 解除绑定
             * @return void
             * **/
            private function UnBinding():void {
                //解除绑定
                watcher1.unwatch();
                watcher2.unwatch();
            }        
        ]]-->
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="动态绑定" click="Binding();"/>
        <mx:Button label="解除绑定" click="UnBinding();"/>
    </mx:ApplicationControlBar>

    

    <mx:VBox width="200" height="200">

        <mx:Spacer height="30"/>

        <mx:TextInput id="txt1"/>
        <mx:TextInput id="txt2"/>

        <mx:Spacer height="30"/>

        <mx:ComboBox id="comb">
            <mx:dataProvider>
                <mx:Array>
                    <mx:String>Beijing</mx:String>
                    <mx:String>Shanghai</mx:String>
                    <mx:String>Hangzhou</mx:String>
                </mx:Array>
            </mx:dataProvider>
        </mx:ComboBox>

        <mx:TextInput id="txtComb"/>
        </mx:VBox>
</mx:Application>

上一篇:R语言绘图技巧导出高清图方法

栏    目:

下一篇:Swift使用表格组件实现单列表

本文标题:Flex 动态绑定BindingUtils.bindProperty

本文地址:http://www.codeinn.net/misctech/225393.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有