隨筆-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
          主站蜘蛛池模板: 宁武县| 汉阴县| 图们市| 临江市| 塔城市| 龙州县| 哈尔滨市| 什邡市| 台东市| 萍乡市| 嘉定区| 沁阳市| 建始县| 大邑县| 双流县| 平原县| 霍林郭勒市| 阿荣旗| 金昌市| 南城县| 乐安县| 广西| 荥经县| 岱山县| 叶城县| 咸宁市| 枣强县| 博兴县| 乌拉特中旗| 东阳市| 洪江市| 科技| 石楼县| 宁远县| 隆德县| 北票市| 东阿县| 新干县| 茶陵县| 南部县| 信宜市|