我花了将近 1 周的时间来学习使用对象而不是数组。我认为调用它们并创建一些对象并设置它们的属性很容易。但是我现在无法访问它们,我尝试了这个:
function onBoxClick(event:MouseEvent):void {
var str:String = event.currentTarget.name;
trace(str);
str = str.substring(str.indexOf("_") + 1);
trace(getChildByName("copy_" + str)); // trying to trace an object by name
}
我的问题是是否有处理对象的实用方法,否则使用它们的目的是什么。
编辑:这是我用来创建影片剪辑和其他东西的函数:
function addBoxes(isUpdate:Boolean):void {
var copyOne:Object = getReadOnlyValues();
copyOne.name = "copy_" + num;
// Set default mc1 settings
var settings1:Object = copyOne.mc1Settings;
for(var num2:String in settings1) {
copyOne.mc1[num2] = settings1[num2];
}
// Set default mc1text settings
var settings2:Object = copyOne.mc1TextSettings;
for(var num3:String in settings2) {
copyOne.mc1Text[num3] = settings2[num3];
}
copyOne.mc1.x = nextXpos;
copyOne.mc1.name = "captionBox_" + num;
addChild(copyOne.mc1);
copyOne.mc1.addEventListener(MouseEvent.CLICK, onCaptionClick);
copyOne.mc1Text.name = "captionBoxText_" + num;
copyOne.mc1.addChild(copyOne.mc1Text);
// ---------------------------------------------------------------
// Set default mc2 settings
var settings4:Object = copyOne.mc2Settings;
for(var num4:String in settings4) {
copyOne.mc2[num4] = settings4[num4];
}
// Set default mc2text settings
var settings5:Object = copyOne.mc2TextSettings;
for(var num5:String in settings5) {
copyOne.mc2Text[num5] = settings5[num5];
}
copyOne.mc2.x = nextXpos;
copyOne.mc2.y = copyOne.mc1.height;
copyOne.mc2.name = "box2_" + num;
addChild(copyOne.mc2);
copyOne.mc2Text.name = "box2BoxText_" + num;
copyOne.mc2.addChild(copyOne.mc2Text);
copyOne.mc2.addEventListener(MouseEvent.CLICK, onBoxClick);
if (num / subunits is int) {
trace (num);
// createMc("normalBox", true);
}
nextXpos = nextXpos + copyOne.mc2.width;
// traceObj(copyOne);
// traceObj(getReadOnlyValues());
}
我在一个循环中调用了这个函数,所以我创建了许多电影剪辑。现在我无法访问对象的属性及其子项(例如文本字段)。
我在舞台上拥有的对象:Movieclips 和 textfields
它们来自哪里:上面的函数
我想用它们做什么:跟踪movieclips 和 textfields(由对象持有)以更改它们的子项(textfield)文本
会发生什么而不是我的期望:跟踪代码输出未定义而不是给我对象类型trace(getChildByName("copy_" + str)); // trying to trace an object by name
是否有一种实用的方法可以访问名称为“copy_1”的对象及其名称为“box2_1”(movieclip)的属性?