我制作了一个fla文件、一个one.as文件、一个two.as文件
fla文件的情况如下面两个图所示:
对于one.as、two.as如果内容如下则一切正常:
package {
import flash.display.Sprite;
public class one extends Sprite {
public var why;
function one() {
super();
init();
}
function init() {
this.name="one";
this.why=88
var two_mc=new two();
addChild(two_mc);
two_mc.shuchu();
}
}
}
package {
import flash.display.Sprite;
public class two extends Sprite {
function two() {
super();
}
function shuchu() {
trace(this.parent.name);
}
}
}
但如果把two.as的内容改成如下所示就不行了:
package {
import flash.display.Sprite;
public class two extends Sprite {
function two() {
super();
}
function shuchu() {
trace(this.parent.why);
}
}
}
这时报错为:1119: 访问可能未定义的属性 why (通过 static 类型 flash.display

isplayObjectContainer 引用)
请问name与why同样都是one的属性,为什么不能同样访问呀?
想了一下如果把上面两个as文件改成如下所示也可以解决问题:
package {
import flash.display.Sprite;
public class one extends Sprite {
var why;
function one() {
super();
init();
}
function init() {
this.name="one";
this.why=88
var two_mc=new two(this);
addChild(two_mc);
two_mc.shuchu();
}
}
}
package {
import flash.display.Sprite;
public class two extends Sprite {
var pt;
function two(_p) {
super();
this.pt=_p;
}
function shuchu() {
trace(this.pt.why);
}
}
}
但上面这种方法我觉得有些麻烦,请问如何才能直接访问this.parent的所有属性呀?