我正在创建一个简单的iPhone游戏(但我所在的课程要求我使用Flash ...),而且我正在尝试从游戏中移除对象时遇到了一个主要问题。”错误#2025提供的DisplayObject必须是调用者的孩子。“尝试removeChild();
这款游戏是一个动态的时间浪费bubblewrap游戏,有无限的“刷新”的阶段。一旦用户弹出所有的泡泡,就会随机生成。 (当数组为空时,请再次拨打setup()
。)
现在,我有五种不同颜色的气泡图形中的一种,它们是通过代码从库中拉出并随机放置在舞台上的。不过,我不喜欢重叠,所以我给每个泡泡都设置了一个小方格,因此当它们随机放置并重叠时,它们会自动弹出。由于某种原因,当我试图删除气泡它给我
错误#2025提供的DisplayObject必须是调用者的子项。
我试过把舞台添加到addChild
和removeChild
,但是我得到了同样的错误。
import flash.events.*;
import flash.display.*;
var bubbles:Array = new Array();
var b:BlueBubble = new BlueBubble();
var b2:GreenBubble = new GreenBubble();
var b3:PinkBubble = new PinkBubble();
var b4:PurpleBubble = new PurpleBubble();
var b5:YellowBubble = new YellowBubble();
// values to be tweaked later
var bNum:uint = 1;
var maxSize:uint = 100;
var minSize:uint = 1;
var range:uint = maxSize - minSize;
var tooBig:uint = 100;
function init():void {
setup();
stage.addEventListener(Event.ENTER_FRAME, onEveryFrame);
}
function setup():void {
for (var i:uint=0; i<bNum; i++) {
// blue
b.width = Math.ceil(Math.random() * range) + minSize;
b.height = b.width;
b.x = Math.random()*(stage.stageWidth - b.width);
b.y = Math.random()*(stage.stageHeight - b.height);
bubbles.push(b);
stage.addChild(b);
// green
b2.width = Math.ceil(Math.random() * range) + minSize;
b2.height = b2.width;
b2.x = Math.random()*(stage.stageWidth - b2.width);
b2.y = Math.random()*(stage.stageHeight - b2.height);
bubbles.push(b2);
stage.addChild(b2);
// pink
b3.width = Math.ceil(Math.random() * range) + minSize;
b3.height = b3.width;
b3.x = Math.random()*(stage.stageWidth - b3.width);
b3.y = Math.random()*(stage.stageHeight - b3.height);
bubbles.push(b3);
stage.addChild(b3);
// purple
b4.width = Math.ceil(Math.random() * range) + minSize;
b4.height = b4.width;
b4.x = Math.random()*(stage.stageWidth - b4.width);
b4.y = Math.random()*(stage.stageHeight - b4.height);
bubbles.push(b4);
stage.addChild(b4);
// yellow
b5.width = Math.ceil(Math.random() * range) + minSize;
b5.height = b5.width;
b5.x = Math.random()*(stage.stageWidth - b5.width);
b5.y = Math.random()*(stage.stageHeight - b5.height);
bubbles.push(b5);
stage.addChild(b5);
//add event listeners for bubbles later
}
}
function onEveryFrame(e:Event) {
for (var i:uint=0; i<bubbles.length; i++) {
bubbles[i].width++;
bubbles[i].height++;
if (bubbles[i].height >= tooBig && bubbles[i].width >= tooBig) {
bubbles[i].height = tooBig;
bubbles[i].width = tooBig;
}
// Blue hit testing
if (b2.hitGreen.hitTestObject(b.hitBlue)) {
removeChild(b);
}
if (b3.hitPink.hitTestObject(b.hitBlue)) {
removeChild(b);
}
if (b4.hitPurple.hitTestObject(b.hitBlue)) {
removeChild(b);
}
if (b5.hitYellow.hitTestObject(b.hitBlue)) {
removeChild(b);
}
// Other hit testing...
}
}
init();
好了,那种工作,换以前的错误“错误#1009:无法访问空对象引用的属性或方法。” ......但是我所了解的东西没有任何东西是空的,那为什么要这么做? – user1769210