隨筆-75  評論-193  文章-5  trackbacks-0
          Another option is to use implicit getters and setters. Implicit getters and setters are declared as methods, but they look like properties. The syntax for a getter is as follows:

          public function get name(  ):Datatype {
          }

          The syntax for a setter is as follows:

          public function set name(value:Datatype):void {
          }

          這樣在代碼中調用counter.count=5時相當于調用了set count(5)方法。

          Counter類如下:
          public class Counter {
              private var _count:uint;
              public function Counter(  ) {
                  _count = 0;
              }
              public function get count(  ):uint {
                  return _count;
              }
              public function set count(value:uint):void {
                  if(value < 100) {
                      _count = value;
                  }
                  else {
                      throw Error(  );
                  }
              }
          }
          posted on 2007-01-13 14:53 The Matrix 閱讀(573) 評論(0)  編輯  收藏 所屬分類: Flex
          主站蜘蛛池模板: 法库县| 铁岭市| 大余县| 家居| 吉木乃县| 黔江区| 金溪县| 金堂县| 彰化市| 航空| 三原县| 望江县| 桐梓县| 普兰县| 宁波市| 巴彦县| 洛宁县| 原平市| 牡丹江市| 枞阳县| 陇西县| 岑巩县| 普兰店市| 祁东县| 海宁市| 汽车| 新巴尔虎右旗| 靖州| 东源县| 无为县| 昭平县| 乳山市| 金寨县| 郁南县| 虎林市| 诏安县| 湛江市| 三江| 慈溪市| 通城县| 瑞丽市|