作者no1kk (心中在下雨)
看板Flash
标题[问题] 关於自订类别 (AS2)
时间Wed May 13 16:50:41 2009
最近开始练习写自订类别
首先先以实做分数的加减乘除开始
但是我遇到了一个问题
类别的内容大致上是
class myclass.test.test1{
private var _mother:Number;//分母
private var _son:Number;//分子
public function test1(p_s:Number, p_m:Number) {
this._mother = p_m;
this._son = p_s;
}
public function get mother():Number {
return this._mother;
}
public function get son():Number {
return this._son;
}
public function set mother(value:Number):Void {
this._mother = value;
}
public function set son(value:Number):Void {
this._son = value;
}
//加法
public function add(num:test1):test1{
this._son=this._son*num._mother+num._son*this._mother;
this._mother=this._mother*num._mother;
return this;
}
.
.
.
}
假设我在使用时
var num:test1=new test1(3,5);
当我
trace(num);
现在会出现
[object Object]
这样的东西
但是我希望他出现的是
3/5
就像当我使用Point类别时
var pt:Point=new Point(20,50);
trace(pt);
得到的结果是
(x=20, y=50)
但是同时又不会影响到
var pt2=pt;
这样的式子
应该要怎样写呢?
感恩
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.31.193.1
※ 编辑: no1kk 来自: 61.31.193.1 (05/13 16:52)