【问题标题】:function parameter with FLEX code带有 FLEX 代码的函数参数
【发布时间】:2011-12-12 07:57:39
【问题描述】:

我在 Flex 手册中找到了 MXML 和 ActionScript 代码。问题在于“val”变量应该作为参数传递给 updateMyString() 函数调用语句,但它不会在代码中发生。这是为什么呢?

<?xml version="1.0"?>
<!-- binding/BindSetterAS.mxml -->
<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">
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.binding.utils.*;
            import mx.events.FlexEvent;
            // Method called when myTI.text changes.
            public function updateMyString(val:String):void {
                myTA.text = val.toUpperCase();
            }
            <!-- Event listener to configure binding. -->
            public function mySetterBinding(event:FlexEvent):void {
                var watcherSetter:ChangeWatcher = 
                    BindingUtils.bindSetter(updateMyString, myTI, "text");
            }
        ]]>
    </fx:Script>
    <s:Label text="Bind Setter using setter method"/>
    <s:TextInput id="myTI" 
        text="Hello Setter" />
    <s:TextArea id="myTA" 
        initialize="mySetterBinding(event);"/>
</s:Application>

【问题讨论】:

    标签: apache-flex actionscript


    【解决方案1】:

    文档说BindingUtils.bindSetter 需要一个带有一个参数的 setter 函数:

    setter:Function — 当链的当前值改变时使用参数调用的 Setter 方法

    在这种情况下,val 参数将设置为链的当前值。你可以在这里阅读:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/binding/utils/BindingUtils.html#bindSetter

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      var watcherSetter:ChangeWatcher = BindingUtils.bindSetter(updateMyString, myTI, "text");

      函数是这样的:

      bindSetter(functionToCall, objectToBind, PropertyToBind)

      所以,你实际上是在绑定myTI.text。这作为参数传递给functionToCall,即updateMyString。明白了吗?

      【讨论】:

      • 这条评论没问题。令人惊讶的是,它与此评论一起使用。
      • 我知道它可以正常工作,但是我们没有将参数传递给函数怎么会发生......它仍然可以工作。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      相关资源
      最近更新 更多