|
AS 数据类型的一些探索(2)
上回说到要仔细看看,其实我也不知道要怎么看,那就搜贝。搜索null。这里说几个比较有用的。
1、 作为函数的返回值。 2、 作为函数的传入值 3、 在判断中参与条件表达式 4、 某些属性的默认值
举一个MM的例子:
当强制类型转换失败的时候返回null。把MM的例子稍微修改一下:
先定义三个类:
class human { function eat () { trace ("human.eat"); } } class man extends human { function work () { trace ("man.work"); } } class woman { function cry() { trace("woman.cry"); }
} 帧脚本:
var m:man=new man(); var w:woman=woman(m); m.work(); trace("Type_m="+typeof(m)); trace("Type_w="+typeof(w)); 输出:
man.work Type_m=object Type_w=null MM还有一个AS基本数据类型转换的例子,起目的主要说明强制转换为Null和Undefined时,都返回undefined.
var mc:MovieClip; var arr:Array; var bool:Boolean; var num3:Number; var obj:Object; var str:String; _root.createTextField("results",2,100,100,300,300); with(results){ text = "type MovieClip : "+(typeof MovieClip(str)); // returns null text += "\ntype object : "+(typeof Object(str)); // returns object text += "\ntype Array : "+(typeof Array(num3)); // returns object text += "\ntype Boolean : "+(typeof Boolean(mc)); // returns boolean text += "\ntype String : "+(typeof String(mc)); // returns string text += "\ntype Number : "+(typeof Number(obj)); // returns number text += "\ntype Function : "+(typeof Function(mc)); // returns object text += "\ntype null : "+(typeof null(arr)); // returns undefined text += "\ntype undefined : "+(typeof undefined(obj)); // returns undefined }
|
|
|