|
I have a selection mechanic that will select objects underneath a drag gesture. I'm trying to deselect the objects when retracing the gesture backwards... the code bellow works for deselecting objects when going over them again, but i want to limit it to the order the objects are in the array. Essentially so objects can only be deselected in the reverse order they were selected in, including the last. if that makes sense.
(comments are locked)
|
|
Editing: I just noticed that you are using RemoveAt, which means the array is a JS array. Just use Pop():
This would remove the last entry from the array and assign it to LastItem. Shift() would remove from the beginning. it is a built in array. I'm using the Pop like so: But this results in a toggle on the first object. How could access the second last object in the array, i get errors on array[array.length-2]...
Jan 30 '12 at 11:53 PM
Drexster
i.e. i get " Index is less than 0 or more than or equal to the list count." when using: Which works, but i'd like to not have any errors...
Jan 31 '12 at 12:04 AM
Drexster
Bracket any operations on the array with an if (Array[x]) { } In other words, test to make sure there is a value where you are about to manipulate, before you do it. Or if you are going to manipulate selected[selected.length-2], then test to make sure that selected.length >= 2.
Jan 31 '12 at 01:44 PM
Tasarran
Thanks for the help Tassaran. I ended up testing against >2, which worked.
Jan 31 '12 at 05:43 PM
Drexster
(comments are locked)
|
