我有这样的东西:
btn_1.addChild(btn1_text);
btn_2.addChild(btn2_text);
btn_3.addChild(btn3_text);
addChild(btn_1);
addChild(btn_2);
addChild(btn_3);
它是创建按钮的代码的一部分。我想编辑btn1_text
的文本,而不是使用
btn1_text.text = ".....";
但是使用这样的东西:
btn_1.btn1_text.text = "......";
有没有办法做到这一点?
您可以使用 name
和 getChildByName()
的组合:
// Create the button and its textfield
var btn_1:Sprite = new Sprite();
var btn1_text:TextField = new TextField();
btn_1.addChild(btn1_text);
addChild(btn_1);
// Add a name to the textfield
btn1_text.name = "btn1_text";
// Retrieve the textfield using its name and set its content
TextField(btn_1.getChildByName("btn1_text")).text = "...";