我有1到64個按鈕叫做(實例名稱)b1 - b64。我需要將鼠標點擊事件添加到每個按鈕。我目前的代碼是這樣的...如何減少AS3中的按鈕點擊事件代碼
b1.addEventListener(MouseEvent.CLICK, btn1click);
function btn1click(event:MouseEvent)
{
var e = b1;
}
b2.addEventListener(MouseEvent.CLICK, btn2click);
function btn2click(event:MouseEvent)
{
var e = b2;
}
b3.addEventListener(MouseEvent.CLICK, btn3click);
function btn3click(event:MouseEvent)
{
var e = b3;
}
.......
我需要減少這種重複。
你不能讓他們的陣列? – reallynice
類似的問題作爲http://stackoverflow.com/questions/36660246/how-to-write-an-object-name-with--variable-for-iteration-in-as3/36661586 –