这就是我动态添加动画片段的方式
var ClassReference:Class = getDefinitionByName('some_name') as Class;
myBody = new ClassReference();
myBody.name = "curtheme"; // I am giving it an instance name here
addChild(myBody);
然后我有这个动态添加的影片剪辑的很多孩子
var hair:Array = [curtheme.getChildByName('hair1'), curtheme.getChildByName('hair2'), curtheme.getChildByName('hair3'), curtheme.getChildByName('hair4'), curtheme.getChildByName('hair5'), curtheme.getChildByName('hair6'), curtheme.getChildByName('hair7'), curtheme.getChildByName('hair8')];
var top:Array = [curtheme.getChildByName('top1'), curtheme.getChildByName('top2'), curtheme.getChildByName('top3'), curtheme.getChildByName('top4'), curtheme.getChildByName('top5'), curtheme.getChildByName('top6'), curtheme.getChildByName('top7'), curtheme.getChildByName('top8')];
这给出了错误:访问未定义的属性curtheme。显然这是错的,但那我如何通过名字访问其子女?我希望我的问题是直截了当的。
答案 0 :(得分:1)
怎么样:
var curtheme:DisplayObjectContainer = this.getChildByName('curtheme') as DisplayObjectContainer;
var hair:Array = [curtheme.getChildByName('hair1'), curtheme.getChildByName('hair2'), curtheme.getChildByName('hair3'), curtheme.getChildByName('hair4'), curtheme.getChildByName('hair5'), curtheme.getChildByName('hair6'), curtheme.getChildByName('hair7'), curtheme.getChildByName('hair8')];
var top:Array = [curtheme.getChildByName('top1'), curtheme.getChildByName('top2'), curtheme.getChildByName('top3'), curtheme.getChildByName('top4'), curtheme.getChildByName('top5'), curtheme.getChildByName('top6'), curtheme.getChildByName('top7'), curtheme.getChildByName('top8')];
或代替:
curtheme.getChildByName('hair1')
试
var hair:Array = [ this['curtheme']['hair1'], this['curtheme']['hair2'], this['curtheme']['hair3'], ...];