0

我一直在寻找几个小时的答案:

我的程序:

步骤一)当我点击一个按钮时,它通过addchild显示一个位图;第二步)当我点击另一个按钮时,它应该通过removechild删除位图;

步骤 I) 完美,但步骤 II) 不起作用。

您会在下面找到我的代码的某些部分:

首先,我声明:

public var ajoutcarte4:MovieClip;

其次,在我写的主要功能中:

var ajoutcarte4:Bitmap = new Bitmap();

然后,在第一个按钮触发的子函数中,我将 Bitmap 添加到舞台(fl_bitmap 是返回 Bitmap 项的函数):

ajoutcarte4 = fl_bitmap(couleur4+figure4);
ajoutcarte4.x=445;
ajoutcarte4.y=370;
addChild(ajoutcarte4);

到目前为止一切顺利,但是当我想通过由第二个按钮触发的另一个子功能删除孩子时:

removeChild(ajoutcarte4);

它不起作用,因为 ajoutecarte4 显然是空的......当我的状况变红时出现错误 2007......

4

2 回答 2

1

改变这个

public var ajoutcarte4:MovieClip;

public var ajoutcarte4:Bitmap;


然后将这条线完全取出

var ajoutcarte4:Bitmap = new Bitmap();


最后

// add this like with this code
ajoutcarte4 = new bitMap()
ajoutcarte4 = fl_bitmap(couleur4+figure4);
ajoutcarte4.x=445;
ajoutcarte4.y=370;
addChild(ajoutcarte4);
于 2012-01-19T02:15:31.693 回答
0

您已经声明了一个MovieClip 类型的字段ajoutcarte4,但是在您的函数中,您声明了一个Bitmap 类型的局部变量ajoutcarte4,然后将其添加到舞台中。

在第二个函数中,您尝试删除从未实例化过的字段MovieClip,从而产生错误。

将您的声明更改为:

public var ajoutcarte4:Bitmap;

并致电:

ajoutcarte4 = new Bitmap(); 

(没有var)。然后一切都应该正常工作。

于 2012-01-19T01:57:33.327 回答