Flex:访问其他函数中动态添加的RicheEditableText
当我点击用户列表时,会触发函数addTab
:
private var counter:int = 0;
public function addTab():void {
var new vBox:VBox = new VBox();
var textBox:RichEditableText = new RichEditableText();
var nameEm:String = "dynamicTextBox" + counter;
textBox.id = nameEm;
counter++;
var textFlow:TextFlow = new TextFlow();
vbox.addChild(textFlow);
vbox.addChild(textBox);
tabNavigator.add(vBox);
}
在另一个函数中,我想向新创建的文本框添加富文本,但无法访问它。
我尝试了 getChildByName(vbox)
和 vbox.getChildByName(textBox)
,但这似乎不起作用。
When I click on a userlist, the function addTab
is triggered:
private var counter:int = 0;
public function addTab():void {
var new vBox:VBox = new VBox();
var textBox:RichEditableText = new RichEditableText();
var nameEm:String = "dynamicTextBox" + counter;
textBox.id = nameEm;
counter++;
var textFlow:TextFlow = new TextFlow();
vbox.addChild(textFlow);
vbox.addChild(textBox);
tabNavigator.add(vBox);
}
In another function, I would like to add Rich Text to the newly created TextBox, but I can not access it.
I tried getChildByName(vbox)
and vbox.getChildByName(textBox)
, but that doesn't seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要让 childbyname 为 richeditable 文本分配一个名称,如果您想通过计数器获取它,则也为 vbox 提供名称,如此处的示例所示:
如果您知道索引,
那么这将为您提供 RichEditableText。
或者,如果您想在添加到选项卡后立即进行访问,请从
addtab
函数返回 RichEditableText。To get childbyname assigned a name to richeditable text and if you want to get it by counter then give name to vbox also, as in the sample here:
If you know the index then
So this will give you RichEditableText.
Or if you want to get access just after adding in to tab then return RichEditableText from the
addtab
function.详细阐述我的评论,想法是你做这样的事情:
现在,在这个函数之外,你只需要知道你想要的 vBox 的计数器编号。例如:
在没有看到更多代码的情况下,我不知道这是否是最好的方法,但是如果您想用一些动态生成的名称标记您的框并稍后查找它们,这将起作用
< a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#getChildByName%28%29" rel="nofollow">示例文档
Elaborating on my comment, the idea is that you do something like this:
Now, outside this function, you just need to know the counter number of the vBox you want. So for example:
Without seeing more of your code, I don't know if this is the best way to go about it, but if you want to mark your boxes with some dynamically generated name and look them up later, this will work
Example documentation