2011-10-21 26 views
-1

我每次都添加孩子,每次添加孩子时,当我添加下一个孩子时,先前的孩子被删除,这是我的目标。我试图删除我的屏幕上显示的孩子,但没有显示。 这里我的编码如何在ActionScript3中删除子项?

var tf:TextField = new TextField(); 
tf.text = chatData.message;<---------here i add the text dynamically 
listChat.addChild(tf); // <----------------------------------here i added the child 

var t:Timer = new Timer(150); 
t.addEventListener(
TimerEvent.TIMER, 
function(ev:TimerEvent): void 
{ 
    tf.text = tf.text.substr(1) + tf.text.charAt(0); 

} 

); 

t.start(); 
listChat.removeChild(tf);// <----------------------------------here i remove the child 

} 

我该如何删除孩子?任何人都可以帮助我,谢谢!

+0

listChat消除了相同的帧,它被添加在文本字段。同样,我不相信你的计时器中的逻辑会像预期的那样选取文本。 –

+0

好的如何删除儿童先生? – Mercy

+0

您的代码添加添加,然后立即删除孩子,我相信你说:“但没有显示在我的屏幕上”意味着你没有看到它,因为你刚刚删除了孩子。 –

回答

0

最后我得到了答案 这里我的编码

var myFormat:TextFormat = new TextFormat(); 
myFormat.size = 35; 
var tf:TextField = new TextField(); 
tf.maxChars=100; 
tf.text = chatData.message; 
tf.defaultTextFormat=myFormat; 
tf.autoSize = TextFieldAutoSize.LEFT; 
tf.x = tf.y = 100; 
listChat.addChild(tf); 
var t:Timer = new Timer(150); 
t.addEventListener(
TimerEvent.TIMER, 
function(ev:TimerEvent): void{ 
tf.text = tf.text.substr(1) + tf.text.charAt(0);  
} 
); 
t.start(); 
if(listChat!=null) 
for (var i:int = listChat.numChildren-2; i >= 0; i--) 
{ 
listChat.removeChildAt (i);//here i remeve the Child 
} 

} 
相关问题