Flex 动态绑定 Flex 动态绑定BindingUtils.bindProperty

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Flex 动态绑定 Flex 动态绑定BindingUtils.bindProperty

  2021-03-17 我要评论
想了解Flex 动态绑定BindingUtils.bindProperty的相关内容吗,在本文为您仔细讲解Flex 动态绑定的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Flex,动态绑定,BindingUtils,下面大家一起来学习吧。
关键字: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>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们