2016-10-22 18 views
0

私のステージからいくつかのTextfieldを作成して後で削除しようとしています。ループ内のTextFieldを削除する

for(i=0;i<Chars.length;i++){ 
    temp = Chars[i] + "_Label"; 
    _root.createTextField(temp, _root.getNextHighestDepth(), 40, 80+(i*30), 200, 20); 
    this[temp].html = true; 
    this[temp].vScrollPolicy = false; 
    this[temp].selectable = false; 
    this[temp].styleSheet=Stat_style; 
    this[temp].htmlText = "<h4>" + eval(Mares[i] + ".Name") + "</h4>";  
    temp = Chars[i] + "_Health"; 
    _root.createTextField(temp, _root.getNextHighestDepth(), 250, 80+(i*30), 200, 20); 
    this[temp].html = true; 
    this[temp].vScrollPolicy = false; 
    this[temp].selectable = false; 
    this[temp].styleSheet=Stat_style; 
    this[temp].htmlText = "<h4>" + eval(Mares[i] + ".Health") + "</h4>";  
} 

stop(); 


CTRL_Back.onRelease = function() { 
    for(i=0;i<Chars.length;i++){ 
     temp = Chars[i] + "_Label"; 
     this[temp].removeTextField(); 
     temp = Chars[i] + "_Health"; 
     this[temp].removeTextField(); 
    } 
} 

作成パーツはうまく動作します。しかし、私はそれらを削除することはできません。 Char1_Label.removeTextField();によって手動で試してみると動作しますが、なぜ私のループ内で動作しないのか分かりません。

答えて

0

問題の瞬間は、関数定義内でthisを使用しています。この場合は、あなたのコードが書かれているスコープではないCTRL_Backオブジェクトを参照します。だからあなたのスコープに別の参照を使用する必要があります。あなたの場合はthis._parentになりますので、あなたの削除行はこのようになりますthis._parent[temp].removeTextField();

関連する問題