- Joined
- Jan 26, 2014
- Messages
- 1,281
- Reaction score
- 106
- First Language
- Irish
- Primarily Uses
- N/A
So I made this array and added sprites on it.
var lineX = 700;
this._buttonList = [];
for (var i = 0; i < 30; i++) {
var button = new Sprite();
button.bitmap = ImageManager.loadPicture('Item');
button.x = 100;
var line = lineX * i;
button.x = button.x + line;
button.y = 300;
this._buttonList.push(button);
this.addChild(this._buttonList);
}
However, I have a function that wants to remove a certain index value from that array. So, I decided to use the splice function. The splicing works, but the array length stays the same. I figured it is because I am not deleting the certain item. So, how can I delete a sprite from the array? I am using this splice by the way:
function move(arr, val) {
var j = 0;
for (var i = 0, l = arr.length; i < l; i++) {
if (arr !== val) {
arr[j++] = arr;
}
}
arr.length = j;
}
I want to delete index 0 for example, but even if I use move(this._buttonList, 0) it won't delete the first sprite on the array. So how can I remove that certain sprite?
var lineX = 700;
this._buttonList = [];
for (var i = 0; i < 30; i++) {
var button = new Sprite();
button.bitmap = ImageManager.loadPicture('Item');
button.x = 100;
var line = lineX * i;
button.x = button.x + line;
button.y = 300;
this._buttonList.push(button);
this.addChild(this._buttonList);
}
However, I have a function that wants to remove a certain index value from that array. So, I decided to use the splice function. The splicing works, but the array length stays the same. I figured it is because I am not deleting the certain item. So, how can I delete a sprite from the array? I am using this splice by the way:
function move(arr, val) {
var j = 0;
for (var i = 0, l = arr.length; i < l; i++) {
if (arr !== val) {
arr[j++] = arr;
}
}
arr.length = j;
}
I want to delete index 0 for example, but even if I use move(this._buttonList, 0) it won't delete the first sprite on the array. So how can I remove that certain sprite?
