返回顶部

收藏

使用ActionScript进行数据绑定

更多
<s:Application xmlns:fx="<a href="http://ns.adobe.com/mxml/2009">http://ns.adobe.com/mxml/2009"
               xmlns:s="<a href="library://ns.adobe.com/flex/spark">library://ns.adobe.com/flex/spark"
               xmlns:mx="<a href="library://ns.adobe.com/flex/mx">library://ns.adobe.com/flex/mx"
               creationComplete="handleCreationComplete();">
    <fx:Script>
        <![CDATA[
            import mx.binding.utils.BindingUtils;
            import mx.binding.utils.ChangeWatcher;
            private var nameWatcher:ChangeWatcher;
            private function handleCreationComplete():void
            {
                nameWatcher = BindingUtils.bindProperty( nameField, "text",
                                                         nameInput, "text" );
            }
            private function handleClick():void
            {
                if( nameWatcher.isWatching() )
                {
                    nameWatcher.unwatch();
                    btn.label = "watch";
                }
                else
                {
                    nameWatcher.reset( nameInput );
                    btn.label = "unwatch";
                }
            }
        ]]>
    </fx:Script>
    <s:Panel title="User Entry.">
        <s:layout>
            <s:VerticalLayout paddingLeft="5" paddingRight="5"
                              paddingTop="5" paddingBottom="5" />
        </s:layout>
        <s:HGroup verticalAlign="bottom">
            <s:Label text="Name:" />
            <s:TextInput id="nameInput" />
        </s:HGroup>
        <s:HGroup verticalAlign="bottom">
            <s:Label text="You Entered:" />
            <s:RichText id="nameField" />
        </s:HGroup>
        <s:Button id="btn"
                  label="unwatch"
                  click="handleClick();" />
    </s:Panel>
</s:Application>

//该片段来自于http://outofmemory.cn

标签:flash,ActionScript,基础

收藏

0人收藏

支持

0

反对

0

发表评论