我有一个列表和创建的图像占位符数组,其中包含数组对象名称(例如:myArray [a,b]),并从那里加载图像,数组列表作为文件夹名称。 最后创建了一个movieClip来加载它们并在舞台上显示。
现在我想删除它们调用相同的数组列表。
在这里需要帮助......
我的代码如下:
for (var l: int = 0; l < ListArray.length; l++) {
var BookName: MovieClip = new bookThumb();
trace("\n[" + l + "]: " + ListArray[l]);
ImageFoldername = ListArray[l];
var bookImagePath: String = "file://" + File.userDirectory.nativePath.toString() + "/Books/" + ImageFoldername + "/Images/Icon.png";
trace(bookImagePath);
var ImagePlacer: Loader = new Loader;
var ImageURL: URLRequest = new URLRequest(bookImagePath);
ImagePlacer.load(ImageURL);
BookName.addChild(ImagePlacer);
BookName.name = ImageFoldername
addChild(BookName)
BookName.x = FirstBook_x;
BookName.y = FirstBook_y;
BookName.buttonMode = true;
BookName.mouseChildren = false;
BookName.addEventListener(MouseEvent.CLICK, IconSelected);
BookName.alpha = .8
BookName.addEventListener(MouseEvent.MOUSE_OVER, IconMouseOver);
BookName.addEventListener(MouseEvent.MOUSE_OUT, IconMouseOut);
FirstBook_x = FirstBook_x + 250;
}
答案 0 :(得分:0)
由于您将ImageFoldername
分配给每个MovieClip
的{{1}}媒体资源,因此您可以使用name
查找并删除它们:
(注意:AS3中的约定是对类使用getChildByName
,对变量和函数使用UpperCamelCase
。我按照此约定编写了下面的代码。)强>
lowerCamelCase
您可以处理它的另一种方法是将每个书签添加到列表中:
for (var i:int = 0; i < listArray.length; i++) {
var imageFolderName:String = listArray[i];
var bookThumb:BookThumb = getChildByName(imageFolderName) as BookThumb;
if (bookThumb) {
removeChild(bookThumb);
}
}
然后将它们全部删除:
var bookThumbs:Array = [];
for (var i:int = 0; i < listArray.length; i++) {
var bookThumb:Bookthumb = new BookThumb();
bookThumbs.push(bookThumb);
// ...
}
但是最简单删除它们的方法可能只是将它们全部放在一个容器中,然后使用for each (var bookThumb:BookThumb in bookThumbs) {
removeChild(bookThumb);
}
bookThumbs.length = 0;
将它们全部删除:
removeChildren()