您的位置:首页 > 其它

as3: this,stage,root的测试

2010-07-11 21:22 267 查看
在不使用文档类(document class)的情况下,直接在时间轴上写以下代码:

trace("this->" + this,",root->" + root,",stage->" + stage);
trace("this==root? -->",this==root);
trace("this.stage==stage? -->",this.stage==stage);
trace(numChildren);

输出:

this->[object MainTimeline] ,root->[object MainTimeline] ,stage->[object Stage]
this==root? --> true
this.stage==stage? --> true
0

同样的代码,如果放在有文档类(比如Test2.as)的环境中测试(构造函数中),输出如下:

this->[object Test2] ,root->[object Test2] ,stage->[object Stage]
this==root? --> true
this.stage==stage? --> true
0

很明显:没有文档类时,this就是指主时间轴;而在有文档类时,this就是文档类自身的实例;另外不管在哪种条件下 this与root都是等同的,this.stage也stage也是相同的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: