所以我成功地使用 addChild() 从库中添加了一个影片剪辑,但现在我想访问动态添加的影片剪辑中的一些影片剪辑。
我使用了标准的点表示法,并且 getChildByName 也将实例名称传递给它。
我在这里想念什么?
----已编辑----
我尝试了循环并可以通过索引访问它们的建议,但似乎没有那么直观的方式来做到这一点......下面是我之前尝试过的两个示例,它们都返回为“1119:访问可能未定义的属性 nameText 通过静态类型 flash.display:DisplayObject 的引用。” 或“1061:通过静态类型 flash.display:DisplayObject 的引用调用可能未定义的方法 getChildByName。”
点符号示例:
// build circlular display
function buildCircle() {
trace("buildCircle()");
if (viewByState == "assignment") {
var competencyContainer:MovieClip = new MovieClip();
competencyContainer.name = "competencyContainer";
this.addChild(competencyContainer);
var angleSegment:Number = 360 / competenciesArray.length;
var angleSum:Number = 360 - angleSegment / 2;
for (var i:Number = 0; i < competenciesArray.length; i++) {
var competencyInstance:competencyCircle = new competencyCircle();
competencyInstance.name = "competency" + i;
competencyContainer.addChild(competencyInstance);
competencyContainer.getChildByName("competency" + i).x = circleCenter.x - (Math.sin(angleSum * (Math.PI / 180)) * (circleSize / 2));
competencyContainer.getChildByName("competency" + i).y = circleCenter.y - (Math.sin((90 - angleSum) * (Math.PI / 180)) * (circleSize / 2));
competencyContainer.getChildByName("competency" + i).nameText.wordWrap = true;
competencyContainer.getChildByName("competency" + i).nameText.embedFonts = true;
competencyContainer.getChildByName("competency" + i).nameText.htmlText = "COMPETENCY:<br />" + competenciesArray[i].name;
competencyContainer.getChildByName("competency" + i).nameText.setTextFormat(tfTitle, 0, competencyContainer.getChildByName("competency" + i).nameText.text.length - competenciesArray[i].name.length);
competencyContainer.getChildByName("competency" + i).nameText.setTextFormat(tfName, competencyContainer.getChildByName("competency" + i).nameText.text.length - competenciesArray[i].name.length, competencyContainer.getChildByName("competency" + i).nameText.text.length);
competencyContainer.getChildByName("competency" + i).nameText.autoSize = TextFieldAutoSize.CENTER;
competencyContainer.getChildByName("competency" + i).nameText.y = -(competencyContainer.getChildByName("competency" + i).nameText.height / 2);
competencyContainer.getChildByName("competency" + i).filters = [circleDefaultDropShadow];
competencyContainer.getChildByName("competency" + i).selectedIndicator.visible = false;
competencyContainer.getChildByName("competency" + i).hit.buttonMode = true;
competencyContainer.getChildByName("competency" + i).hit.mouseEnabled = true;
competencyContainer.getChildByName("competency" + i).hit.tabEnabled = true;
competencyContainer.getChildByName("competency" + i).hit.mouseChildren = true;
competencyContainer.getChildByName("competency" + i).hit.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent) {
e.target.parent.filters = [circleHoverDropShadow];
});
competencyContainer.getChildByName("competency" + i).hit.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent) {
e.target.parent.filters = [circleDefaultDropShadow];
});
competencyContainer.getChildByName("competency" + i).hit.addEventListener(MouseEvent.CLICK, function(e:MouseEvent) {
e.target.parent.filters = [circleDefaultDropShadow];
e.target.parent.selectedIndicator.visible = true;
});
angleSum -= angleSegment;
trace("end");
trace(i);
trace("\n\n\n");
}
} else if (viewByState == "competency") {
} else {
}
}
buildCircle();
以及使用 .getChildByName() 的示例:
// build circlular display
function buildCircle() {
trace("buildCircle()");
if (viewByState == "assignment") {
var competencyContainer:MovieClip = new MovieClip();
competencyContainer.name = "competencyContainer";
this.addChild(competencyContainer);
var angleSegment:Number = 360 / competenciesArray.length;
var angleSum:Number = 360 - angleSegment / 2;
for (var i:Number = 0; i < competenciesArray.length; i++) {
var competencyInstance:competencyCircle = new competencyCircle();
competencyInstance.name = "competency" + i;
competencyContainer.addChild(competencyInstance);
competencyContainer.getChildByName("competency" + i).x = circleCenter.x - (Math.sin(angleSum * (Math.PI / 180)) * (circleSize / 2));
competencyContainer.getChildByName("competency" + i).y = circleCenter.y - (Math.sin((90 - angleSum) * (Math.PI / 180)) * (circleSize / 2));
competencyContainer.getChildByName("competency" + i).getChildByName("nameText").wordWrap = true;
competencyContainer.getChildByName("competency" + i).getChildByName("nameText").embedFonts = true;
competencyContainer.getChildByName("competency" + i).getChildByName("nameText").htmlText = "COMPETENCY:<br />" + competenciesArray[i].name;
competencyContainer.getChildByName("competency" + i).getChildByName("nameText").setTextFormat(tfTitle, 0, competencyContainer.getChildByName("competency" + i).getChildByName("nameText").text.length - competenciesArray[i].name.length);
competencyContainer.getChildByName("competency" + i).getChildByName("nameText").setTextFormat(tfName, competencyContainer.getChildByName("competency" + i).getChildByName("nameText").text.length - competenciesArray[i].name.length, competencyContainer.getChildByName("competency" + i).getChildByName("nameText").text.length);
competencyContainer.getChildByName("competency" + i).getChildByName("nameText").autoSize = TextFieldAutoSize.CENTER;
competencyContainer.getChildByName("competency" + i).getChildByName("nameText").y = -(competencyContainer.getChildByName("competency" + i).getChildByName("nameText").height / 2);
competencyContainer.getChildByName("competency" + i).filters = [circleDefaultDropShadow];
competencyContainer.getChildByName("competency" + i).getChildByName("selectedIndicator").visible = false;
competencyContainer.getChildByName("competency" + i).getChildByName("hit").buttonMode = true;
competencyContainer.getChildByName("competency" + i).getChildByName("hit").mouseEnabled = true;
competencyContainer.getChildByName("competency" + i).getChildByName("hit").tabEnabled = true;
competencyContainer.getChildByName("competency" + i).getChildByName("hit").mouseChildren = true;
competencyContainer.getChildByName("competency" + i).getChildByName("hit").addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent) {
e.target.parent.filters = [circleHoverDropShadow];
});
competencyContainer.getChildByName("competency" + i).getChildByName("hit").addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent) {
e.target.parent.filters = [circleDefaultDropShadow];
});
competencyContainer.getChildByName("competency" + i).getChildByName("hit").addEventListener(MouseEvent.CLICK, function(e:MouseEvent) {
e.target.parent.filters = [circleDefaultDropShadow];
e.target.parent.getChildByName("selectedIndicator").visible = true;
});
angleSum -= angleSegment;
trace("end");
trace(i);
trace("\n\n\n");
}
} else if (viewByState == "competency") {
} else {
}
}
buildCircle();