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

首頁(yè) > 網(wǎng)站 > WEB開發(fā) > 正文

1.17.檢測(cè)對(duì)象數(shù)據(jù)類型

2024-04-27 13:51:44
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
1.17.1.問(wèn)題
我想檢測(cè)下傳入到方法的對(duì)象是什么類型。
1.17.2.解決辦法
使用is操作符檢測(cè)對(duì)象類型或者是父類對(duì)象的type屬性。
1.17.3.討論
要檢測(cè)一個(gè)對(duì)象的類型,ActionScript提供了is操作符,檢測(cè)對(duì)象類型并返回true或false。如果對(duì)象與測(cè)試目標(biāo)一致或是其子類則返回true,比如,因?yàn)镃anvas對(duì)象繼承自UIComponent,is操作符返回true。如果IComponent測(cè)試它為Canvas類型則返回false。因?yàn)閁IComponent并不是繼承自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));
}
輸出一下內(nèi)容:
uiComponent is UIComponent true
uiComponent is Canvas false
canvas is UIComponent true
類型檢測(cè)最常用到的地方是當(dāng)組件拋出一個(gè)事件時(shí)。在事件處理函數(shù)中檢測(cè)是什么對(duì)象發(fā)出動(dòng)作。
+展開
-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 */
}
}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 临漳县| 呼玛县| 沂水县| 云林县| 卢氏县| 泸水县| 安多县| 永济市| 白沙| 高陵县| 泌阳县| 三原县| 德令哈市| 霞浦县| 松滋市| 罗山县| 龙山县| 淮阳县| 丰镇市| 武邑县| 迭部县| 安乡县| 兴化市| 普兰县| 罗源县| 琼中| 北京市| 靖江市| 神农架林区| 内黄县| 博白县| 钦州市| 保山市| 香格里拉县| 黑水县| 枣庄市| 新源县| 龙南县| 浦县| 延长县| 武川县|