ChangeWatcher的使用

    技术2022-05-20  37

    从网上看了一篇文章介绍ChangeWatcher的使用,不过也不清楚具体用到什么地方,先收藏了再说:

    <?xml version="1.0" encoding="utf-8"?>

    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                   xmlns:s="library://ns.adobe.com/flex/spark"

                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

                   creationComplete="init();">

        <fx: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);

            }

           

            ]]>

        </fx: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>

     

    </s:Application>

     


    最新回复(0)