CGArt-中国CGer中的绿色家园
首页 信息动态 原创排行 互动教程 资源千寻 CG人才 CGArt杂志 艺术设计 CG画廊 CG论坛 酷站欣赏 CG搜索 会员中心
AS 数据类型的一些探索
作者:LeeFJ 编辑: 发布时间:2005年04月02日 05:44:53

[ 1 ]  [ 2 ]  

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
}

[ 1 ]  [ 2 ]  
共有评论0条
更多评论..
作者信息 详细信息
评论人:
验证码:
内容:
 
about us advertisement publish conformity service cooperate associate link site map contact us help jump to the top of page