AS3 Removechild Addchild 问题/错误
我几个小时以来一直在寻找答案:
我的程序:
步骤I)当我单击一个按钮时,它通过addchild显示一个位图; 步骤II)当我点击另一个按钮时,它应该通过removechild删除位图;
步骤 I) 工作完美,但步骤 II) 不起作用。
您将在下面找到我的代码的某些部分:
首先,我声明:
public var ajoutcarte4:MovieClip;
其次,在我编写的主函数中:
var ajoutcarte4:Bitmap = new Bitmap();
然后,在第一个按钮触发的子函数中,我将位图添加到舞台(fl_bitmap 是一个返回的函数)位图项):
ajoutcarte4 = fl_bitmap(couleur4+figure4);
ajoutcarte4.x=445;
ajoutcarte4.y=370;
addChild(ajoutcarte4);
到目前为止一切顺利,但是当我想通过第二个按钮触发的另一个子函数删除子项时:
removeChild(ajoutcarte4);
它不起作用,因为 ajoutecarte4 显然为空...错误 2007 当我的情况变得红色时。 ..
I have been looking for an answer for hours:
My program:
Step I) When I click on a button, it displays a bitmap through addchild;
Step II) When I click on another button, it should remove the bitmap through removechild;
Step I) works perfectly but step II) doesn't work.
You'll find below some parts of my code:
First, I declare:
public var ajoutcarte4:MovieClip;
Secondly, In the main function I wrote:
var ajoutcarte4:Bitmap = new Bitmap();
Then, in a sub function triggered by the first button, I add the Bitmap to the stage (fl_bitmap is a function returning a Bitmap item):
ajoutcarte4 = fl_bitmap(couleur4+figure4);
ajoutcarte4.x=445;
ajoutcarte4.y=370;
addChild(ajoutcarte4);
So far so good but when I want to remove the child through another sub function triggered by a second button:
removeChild(ajoutcarte4);
It doesn't work because ajoutecarte4 is apparently null... Error 2007 when i get red of my condition...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其更改
为
然后完全删除此行
最后
change this
to
Then take out this line completely
And lastely
您已声明了一个 MovieClip 类型的字段 ajoutcarte4,但随后在函数中声明了一个 Bitmap 类型的局部变量 ajoutcarte4,然后将其添加到舞台中。
在第二个函数中,您尝试删除从未实例化的字段 MovieClip - 从而产生错误。
将您的声明更改为:
并调用:(
不带
var
)。然后一切都应该正常工作。You've declared a field ajoutcarte4 of type MovieClip, but then in your function, you declare a local variable ajoutcarte4 of type Bitmap, which is then added to the stage.
In the second function, you try to remove the field MovieClip, which has never been instantiated - and thus produces the error.
Change your declaration to this:
and call:
(without the
var
). Then it all should work correctly.