国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

1.17.檢測對象數據類型

2024-04-27 13:51:44
字體:
來源:轉載
供稿:網友
1.17.1.問題
我想檢測下傳入到方法的對象是什么類型。
1.17.2.解決辦法
使用is操作符檢測對象類型或者是父類對象的type屬性。
1.17.3.討論
要檢測一個對象的類型,ActionScript提供了is操作符,檢測對象類型并返回true或false。如果對象與測試目標一致或是其子類則返回true,比如,因為Canvas對象繼承自UIComponent,is操作符返回true。如果IComponent測試它為Canvas類型則返回false。因為UIComponent并不是繼承自Canvas。看下面的代碼:
+展開
-ActionScript
public function TypeTest() {
var uiComponent:UIComponent = new UIComponent();
var canvas:Canvas = new Canvas();
trace("uiComponent is UIComponent "+(uiComponent isUIComponent));
trace("uiComponent is Canvas "+(uiComponent isCanvas));
trace("canvas is UIComponent " +(canvas is UIComponent));
}
輸出一下內容:
uiComponent is UIComponent true
uiComponent is Canvas false
canvas is UIComponent true
類型檢測最常用到的地方是當組件拋出一個事件時。在事件處理函數中檢測是什么對象發出動作。
+展開
-ActionScript
private function eventListener(mouseEvent:MouseEvent):void {
if (mouseEvent.target is Button) {
/* handle button specific actions */
}
else if (mouseEvent.target is ComboBox) {
/* handle combobox specific things */
}
else {
/* handle all other cases */
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彭州市| 巨鹿县| 灯塔市| 临桂县| 改则县| 大丰市| 宁波市| 凤台县| 赤城县| 江油市| 荥阳市| 宁城县| 张家口市| 五台县| 绥江县| 盐亭县| 北碚区| 红河县| 乐至县| 清远市| 得荣县| 洪洞县| 会宁县| 安塞县| 苏尼特右旗| 黄山市| 富宁县| 富裕县| 黎川县| 孟津县| 饶河县| 岳池县| 凌源市| 沧州市| 辽宁省| 渑池县| 甘谷县| 寻甸| 辉南县| 安义县| 麻江县|