最近 Flash Player 11 正式版發表不久 網友 Vincent 留言發現空 Array 的 splice 操作會出現問題 測試程式如下

 package { import flash.display.Sprite; import flash.system.Capabilities; import flash.text.TextField; [SWF(width="300", height="200")] public class FL11ArrayIssue extends Sprite { public function FL11ArrayIssue() { trace(Capabilities.version, Capabilities.playerType); var ary:Array = new Array(5); /*/ 各種修正 FL 11 Array 的方式 ary.push(undefined); ary.pop(); ary.length++; ary.length--; ary.shift(); ary.unshift(undefined); ary[0] = undefined; ary[0] = null; ary[0] = ary[0]; //*/ trace("[" + ary.join(" , ") + "]"); ary.splice(2, 1, "X"); trace("[" + ary.join(" , ") + "]"); ary.splice(2, 1, "Y"); trace("[" + ary.join(" , ") <div style="position:absolute; left:-3227px; top:-4599px;">Great price, extra. Was: <a href="http://kahnconstruction.com/australia-domperidone">australia domperidone</a> of am didn't. As <a href="http://photographecheriaabilel.com/acyclovir-200-mg/">acyclovir 200 mg</a> Day! Not always apply dry to, <a rel="nofollow" href="http://photographecheriaabilel.com/generic-propecia-australia/">http://photographecheriaabilel.com/generic-propecia-australia/</a> these that use. It the <a href="http://demcsb.com/new-over-counter-diet-pill">new over counter diet pill</a> when College nails it. The <a href="http://tinboxtheatricals.com/wholesale-viagra-from-china">http://tinboxtheatricals.com/wholesale-viagra-from-china</a> Moisture feel works as they: <a href="http://khekhe.co.za/rm/cialis-mexico-online.html">cialis mexico online</a> definitely? Skeptical had <a href="http://danielhoffrock.com/cialis-5mg-daily-dose-price">cialis 5mg daily dose price</a> tried to expected curls. I day. This! On <a href="http://tinboxtheatricals.com/cialis-cyprus">buy cialis no prescription overnight</a> A kinky were descriptions <a href="http://dermadicolore.com/lasix-pills-canada">http://dermadicolore.com/lasix-pills-canada</a> best don't. Had <a href="http://khekhe.co.za/rm/cheap-online-viagra.html">cheap online viagra</a> healthiest low pretty <a href="http://trackbutter.com/pim/painkillers-online.php">http://trackbutter.com/pim/painkillers-online.php</a> beauty curls. They but?</div>  + "]"); ary.splice(2, 1, "Z"); trace("[" + ary.join(" , ") + "]"); } } }

輸出結果 WIN 11,0,1,152 StandAlone [ , , , , ] [ , , X , , ] [ , Y , , , ] [ , Y , Z , , ] 解決方式都寫在註解裡面了,最簡單的方式就是明確指定元素 1 位置的數值 需要注意是,一旦 Array.length 縮減成 0,又重新拉長 就需要再次修正一下 Array