as3: this,stage,root的测试

在不使用文档类(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也是相同的。

posted @ 2010-07-11 21:22  菩提树下的杨过  阅读(1528)  评论(4编辑  收藏  举报