国产探花免费观看_亚洲丰满少妇自慰呻吟_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 */
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 萨嘎县| 东港市| 南昌县| 平阴县| 内黄县| 松溪县| 桦甸市| 抚宁县| 桂东县| 上虞市| 榆林市| 东海县| 轮台县| 长兴县| 许昌县| 镇平县| 寿宁县| 青州市| 延寿县| 平陆县| 汪清县| 合作市| 丘北县| 宜阳县| 滨海县| 大方县| 红河县| 绥棱县| 金堂县| 海盐县| 通城县| 安龙县| 洪洞县| 辉南县| 亳州市| 福贡县| 岐山县| 黎平县| 定襄县| 康定县| 德兴市|