国产探花免费观看_亚洲丰满少妇自慰呻吟_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 */
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成武县| 岳阳县| 武夷山市| 鲁山县| 泰来县| 白河县| 浦江县| 彭州市| 忻州市| 城市| 阜阳市| 龙游县| 龙井市| 乳山市| 宕昌县| 枞阳县| 呼和浩特市| 武安市| 扎赉特旗| 昌平区| 大渡口区| 高安市| 塔城市| 温宿县| 普陀区| 武城县| 松潘县| 平遥县| 南皮县| 元阳县| 永登县| 淮南市| 新巴尔虎右旗| 天峨县| 喀什市| 高淳县| 满洲里市| 射阳县| 岳阳市| 剑阁县| 曲水县|