as3.0学习小记(3)

      flashcs3 2006-11-22 12:40

学习get 和set.(今天犯了一个错误,把uint打成unit了,找了半小时,最后才找到,,,,),

Counter.as代码如下:

package{
 public class Counter{
  private var _count:uint;
  public function Counter(){
   _count=2;
  }
  public function get Count():uint{
   return _count;
  }
  public function set Count(value:uint):void{
   if(value<30){
    _count=value;
   }else{
    throw Error();
   }
  }   
 }
}

Counter.fla代码及输出效果:

var myCounter:Counter=new Counter();
trace(myCounter.Count)//3;
myCounter.Count=12
trace(myCounter.Count);//12
myCounter.Count=112
trace(myCounter.Count);//Error   at Counter/set Count()    at Timeline0_f56590c911c64248a48a2797499597f/::frame1()

 

标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}