Flex的返回ChangeWatcher不起作用 [英] Flex ChangeWatcher doesn't work

查看:125
本文介绍了Flex的返回ChangeWatcher不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现并收集了一些定制机型之间的绑定刚刚开始涉足与整个mx.binding。*。我想这个简单,剥离下来的例子,但是不能绑定正常工作。有谁能告诉我,我要去哪里错了?

I'm trying to implement a binding between some custom-built models and just beginning to dabble with the whole mx.binding.* collection. I tried this simple, stripped down example, but can't get the binding working correctly. Can somebody tell me where I'm going wrong?

// Model
package  
{
 import flash.events.EventDispatcher;

 public class Model extends EventDispatcher
 {
  private var m_count:uint = 0;

  [Bindable]
  public function get Count():uint
  {
   return this.m_count;
  }

  public function set Count(c:uint):void
  {
   this.m_count = c;
  }
 }
}

这是什么应用程序MXML看起来像

And this is what the application MXML looks like

// MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:core="*" creationComplete="this.init();">
 <mx:Script>
  <![CDATA[
  import flash.events.Event;
  import flash.utils.describeType;
  import mx.binding.utils.ChangeWatcher;

  [Bindable]
  public var model:Model;

  public function init():void
  {
   var _this:Object = this;

   this.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
    _this.model.Count++;
   });


   this.model = new Model();

   trace(ChangeWatcher.canWatch(this.model, "Count")); // This always returns false for some reason
   trace(describeType(this.model));
  }

  public function UpdateText(s:String):void
  {
   trace(s);
  }
  ]]>
 </mx:Script>
 <mx:Text text="{this.model.Count}" creationComplete="trace(this);" />
</mx:WindowedApplication>

更新:我想一个更裸机版本,如下图所示。

Update: I tried an even more bare-bones version as shown below.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="this.m_init();">
    <mx:Script>
        <![CDATA[
        import mx.binding.utils.ChangeWatcher;

        [Bindable] public var m:Object = new Object();

        public function m_init():void
        {
            trace(ChangeWatcher.canWatch(this, "m"));
        }
        ]]>
    </mx:Script>
    <mx:Text text="{this.m}" />
</mx:Application>

不过。没有。工作。 ChangeWatcher.canWatch仍然返回false,虽然文本框不显示[对象的对象。

Still. Doesn't. Work. ChangeWatcher.canWatch still returns false, although the textfield does display [object Object].

推荐答案

我删除obj的文件夹内的所有文件的项目之下,这个问题似乎已经消失。这可能是该FlashDevelop中是使用旧编译的二进制文件移出此文件夹,这使得输出不同步与源$ C ​​$ C的。

I removed all files inside the obj folder under the project and the problem seems to have gone away. It might have been that FlashDevelop was using older compiled binaries out of this folder, which made the output go out of sync with the source code.

证据来支持这种在于两点。更改SDK并没有影响到我自己的电脑,它排除了任何SDK-具体问题的输出。所以,我在同一台计算机和复制粘贴的code成一个在另一个IDE中创建一个新项目。这一次,它的工作。这时候,我想这可能是缓存并走进去,将其删除。

Evidence to support this lies in two things. Changing the SDK did not affect the output on my own computer, which ruled out any SDK-specific issues. So I created a new project in another IDE on the same computer and copy-pasted the code into that one. This time it worked. That's when I thought it might be the cache and went in and deleted it.

在事后看来,我应该给它改名,后来又试图重新编译与旧的缓存到位。这将是决定性的。

In hindsight, I should have renamed it, and later tried to compile with the old cache in place again. That would have been conclusive.

这篇关于Flex的返回ChangeWatcher不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆