看板 Flash 關於我們 聯絡資訊
※ 引述《Sibevin (天才藝術家)》之銘言: : 我在影格中寫了一個迴圈如下 : var i:Number = 0; : var chosenPart:Number = 0; : for (i=1; i<=5; i++) { : eval("part_"+i+"_mc").onPress = function() { : chosenPart = i; : } : } : 原本想做成只要選part_1_mc~part_5_mc其中的一塊 : chosenPart就會對應到它的號碼 : 例如:選part_1_mc,則chosenPart=1; : 選part_2_mc,則chosenPart=2; : ... : 但結果卻是 : 選part_1_mc,則chosenPart=6; : 選part_2_mc,則chosenPart=6; : ... : 我可以理解問題出在哪裡,因為迴圈的結果是 : part_1_mc.onPress = function() { : chosenPart = i; : } : part_2_mc.onPress = function() { : chosenPart = i; : } : ... : 可是我想要的是 : part_1_mc.onPress = function() { : chosenPart = 1; : } : part_2_mc.onPress = function() { : chosenPart = 2; : } : ... : 雖然可以不用迴圈來解決這個問題 : 但如果要做好幾個這種東西 : 顯然這個方法不是明智之舉 : 要怎樣修改程式碼才能有我想要的結果 : 請各位幫幫我吧 for (i=1; i<=5; i++) { eval("part_"+i+"_mc").onPress = function() { chosenPart = int(this._name.substr(5,1)); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.48.185
Sibevin:瞬間解答我的疑惑~真的非常感謝 10/28 14:31