How do I remove an items from a data bound array? My code follows.
for(var i = 0; i < listBox.selectedIndices.length; i++) { var toRemove = listFiles.selectedIndices[i]; dataArray.splice(toRemove, 1); }
Thanks in advance!
Edit Here is my swf. The Add Photos works except when you remove items. http://www.3rdshooter.com/Content/Flash/PhotoUploader.html
- Add 3 photos different.
- Remove 2nd photo.
- Add a different photo.
- SWF adds the 2nd photo to the end.
Any ideas on why it would be doing this?
Edit 2 Here is my code
private function OnSelectFileRefList(e:Event):void { Alert.show('addstart:' + arrayQueue.length); for each (var f:FileReference in fileRefList.fileList) { var lid:ListItemData = new ListItemData(); lid.fileRef = f; arrayQueue[arrayQueue.length]=lid; } Alert.show('addcomplete:' + arrayQueue.length); listFiles.executeBindings(); Alert.show(ListItemData(arrayQueue[arrayQueue.length-1]).fileRef.name); PushStatus('Added ' + fileRefList.fileList.length.toString() + ' photo(s) to queue!'); fileRefList.fileList.length = 0; buttonUpload.enabled = (arrayQueue.length > 0); } private function OnButtonRemoveClicked(e:Event):void { for(var i:Number = 0; i < listFiles.selectedIndices.length; i++) { var toRemove:Number = listFiles.selectedIndices[i]; //Alert.show(toRemove.toString()); arrayQueue.splice(toRemove, 1); } listFiles.executeBindings(); Alert.show('removecomplete:' + arrayQueue.length); PushStatus('Removed photos from queue.'); buttonRemove.enabled = (listFiles.selectedItems.length > 0); buttonUpload.enabled = (arrayQueue.length > 0); }
It would definitely be helpful to know two things:
Which version of ActionScript are you targeting?
Judging from the behavior of your application, the error isn’t occurring when the user removes an item from the list of files to upload. Looks more like an issue with your logic when a user adds a new item to the list. Any chance you could post that code as well?
UPDATE:
Instead of:
arrayQueue[arrayQueue.length]=lidTry:
arrayQueue.push(lid)That will add a new item to the end of the array and push the item in to that spot.
UPDATE 2:
Ok, did a little more digging. Turns out that the fileList doesn’t get cleared every time the dialog is opened (if you’re not creating a new instance of the FileReferenceList each time the user selects new files). You need to call splice() on the fileList after you add each file to your Array.
Try something like this in your AddFile() method…
That will keep the fileList up to date rather than holding on to previous selections.