actionscript-3 - 尝试在 Flash AS3.0 中使用 BindingUtils

标签 actionscript-3 apache-flex flex4

我无法使此代码在包含 Flex SDK 4.0 的 AS3.0 ( Flash ) 中工作。

 import mx.binding.utils.*;


 [Bindable]
 var myValue:int = 0;
 var cw:ChangeWatcher = BindingUtils.bindSetter(myValueChanged, this, "myValue");
 addEventListener( Event.ENTER_FRAME , ef);

 function ef(e:Event):void
 {
    trace("hello",getTimer());
    myValue = getTimer();
 }

 function myValueChanged(o:Object):void
 {
    trace("myValue: " + myValue.toString());
 }

我得到的输出是:

myValue: 0
hello 157
hello 168
hello 171
hello 177
....
....

等等。

但我希望正确的输出应该是:

myValue: 0
hello 157
myValue: 157
hello 168
myValue: 168
hello 171
myValue: 171
hello 177
myValue: 177
....
....

谢谢。

最佳答案

数据绑定(bind)仅适用于 Flex。

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx" enterFrame="ef(event)">

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.binding.utils.*;

            [Bindable]
            public var myValue:int = 0;
            private var cw:ChangeWatcher = BindingUtils.bindSetter(myValueChanged, this, "myValue");

            private function ef(e:Event):void
            {
                trace("hello", getTimer());
                myValue = getTimer();
            }

            private function myValueChanged(o:Object):void
            {
                trace("myValue: " + myValue.toString());
            }
        ]]>
    </fx:Script>
</s:WindowedApplication>

关于actionscript-3 - 尝试在 Flash AS3.0 中使用 BindingUtils,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13904382/

相关文章:

闪存并行编程

actionscript-3 - AS3 在添加到另一个 AS 类文件上的舞台时访问 MovieClip

actionscript-3 - 在 Flex 中将 String 转换为 Date 对象

apache-flex - 我应该使用PurePDF还是AlivePdf

actionscript-3 - 将 MovieClip 拖动到一个圆圈

javascript - 将对象从flex传递到javascript

apache-flex - Flex 中文本/标签的下划线样式

java - 如何在带有 Mate Framework 的 Flex 中使用强类型远程服务对象?

apache-flex - Spark DropDownList 作为 AdvancedDataGrid 中的 itemEditor 的问题

actionscript-3 - 我的错误在哪里? (Flash CS6 AS3错误: 1120)