2017-05-04 8 views
0

のために供給さnilのキーIは、グループを作成し、そして関数を呼び出す、次のイベントリスナーを追加しました:にremoveEventListener:プロパティ参照

catinBalloon:addEventListener("touch", catinBalloontouch) 

はその後、私はグループcatinBalloonに2つのオブジェクトを挿入しにグループを追加しましたテーブル:

他の機能の一部として、テーブルをループしてリスナーイベントを削除する必要があります。

for i = #catandBalloonTable, 1, -1 do 
print_r(catandBalloonTable[i]) 
    catandBalloonTable[i]:removeEventListener("touch", catinBalloontouch) 

end 

ますprint_rの出力誤差がある前に:

04:20:03.364 table: 0DACC088 { 
04:20:03.364 [_proxy] => userdata: 0DAD20E0 
04:20:03.364 [_functionListeners] => table: 0DACC088 { 
04:20:03.364        [touch] => table: 0DADA0C0 { 
04:20:03.364           [1] => function: 04080198 
04:20:03.364           [2] => function: 0DA0E6E0 
04:20:03.364           } 
04:20:03.364       } 
04:20:03.364 [activeObjectWord] => "ant" 
04:20:03.364 [_class] => table: 0DACC088 { 
04:20:03.364     [removeEventListener] => function: 04245CE8 
04:20:03.364     [addEventListener] => function: 04247968 
04:20:03.364     [__index] => table: 0425AE40 { 
04:20:03.364         *table: 0425AE40 
04:20:03.364        } 
04:20:03.364    } 
04:20:03.364 [removeSelf] => function: 0433B9B8 
04:20:03.364 [active] => "yes" 
04:20:03.364 [activeObjectSound] => userdata: 0A0CAAE0 
04:20:03.364 } 

し、エラーがある:

04:20:03.364 ERROR: nil key supplied for property lookup. 
04:20:03.364 stack traceback: 
04:20:03.364 [C]: ? 
04:20:03.364 ?: in function 'removeEventListener' 
04:20:03.364 ?: in function 'removeEventListener' 
04:20:03.364 ?: in function 'removeEventListener' 

ありがとうございました。

答えて

2

提供したハンドラ関数(catinBalloontouch)がこのスコープに存在しない場合、このエラーが発生します。あなたの問題を解決する1つの方法は、前方参照を使用することです。

-- top of your file 
local catinBalloontouch 
... 
function catinBalloontouch(event) -- now you don't need use key word local 
    ... 
end 
... 
for i = #catandBalloonTable, 1, -1 do 
print_r(catandBalloonTable[i]) 
    catandBalloonTable[i]:removeEventListener("touch", catinBalloontouch) 

end 
関連する問題