- Type Checking
在ActionScript 3.0 裡如果要做型態檢驗,可以透過 is 和 as 這兩個operator來達成,下面是一個簡單的範例:
import com.xinyu.geom.Ball;
import com.xinyu.geom.Triangle;
var ball:Ball = new Ball();
addChild(ball);
trace(ball is Ball);
trace(ball is Triangle);
trace(ball is Sprite);
trace(ball as Ball);
trace(ball as Triangle);
trace(ball as Sprite);
輸出畫面如下:
false
true
[object Ball]
null
[object Ball]
No comments:
Post a Comment