我的代碼工作正常。假設用戶按1時輸入一個圖像,當他/她按下2時換出另一個圖像。但是,如果在先按下相同的號碼後按1或2,則會出現#2025錯誤。例如:按1,然後再按1。ActionScript 3:錯誤#2025
ArgumentError:錯誤#2025:提供的DisplayObject必須是調用者的子項。 在flash.display一::級DisplayObjectContainer/removeChild之() 在warren_fla :: MainTimeline/reportKeyDown2()
代碼
import flash.events.KeyboardEvent;
var bdata = new image1(stage.stageWidth, stage.stageHeight);
var bdata2 = new image2(stage.stageWidth, stage.stageHeight);
var bmp = new Bitmap(bdata);
var bmp2 = new Bitmap(bdata2);
function reportKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == 49) {
//trace("1 is pressed");
bmp.x = 230;
bmp.y = 150;
addChild(bmp);
}
if (contains(bmp2)) {
removeChild(bmp2);
}
}
function reportKeyDown2(event:KeyboardEvent):void
{
if (event.keyCode == 50) {
//trace("2 is pressed");
bmp2.x = 230;
bmp2.y = 150;
addChild(bmp2);
removeChild(bmp);
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown2);
謝謝。 +1效率 – Warren