2011-10-21 27 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 
} 

} 
相關問題