原创  关于Bindable 收藏

Training from the Source Lesson 5 section 3:

对一个类进行绑定声明
package   ns1{
      [Bindable]
      class Class1{
          public var n:uint;            //为什么声明为public?请看下去
          public function Class1(_n:uint){
              n=_n;
          }
          public function get nn():uint{return n;}
      }
}

MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
  <![CDATA[
   import test.ClassTest;
   [Bindable]
   private var s:ClassTest=new ClassTest(3);
  ]]>
 </mx:Script>
 <mx:Label text="{s.nn}" />
                <mx:Label text="{s.n}"  />  <!--    就为这个把n声明为public      -->
</mx:Application>
开始以为这样声明后,此类的实例就会不用再声明Bindable可以直接给组件用
但试了下,不行。原书中的代码,类的实例一样要加Bindable。
不解..

再仔细看:
means that every property in the class can be bound to controls or other data structures.
试了试直接通过读取实例属性而非通过函数读取
报了个警告
DONE..

原来Bindable了的类的实例中所有属性都可以绑定...
不过这样的直接通过读取属性的情况还是较少吧?

发表于 @ 2007年08月19日 22:18:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:FLEX | 新一篇:关于state

  • 发表评论
  • 评论内容:
  •  
Copyright © Iptton
Powered by CSDN Blog