Andy79#17045
Hi guys,
What is the correct way to remove all vObjects (except the first vObject) from a specific layer
on a CanvasViewer using javascript?
I'm finding that every second object I try to remove is null for some reason...
In one example, I have 7 objects on the 3rd layer. I want to remove all vObjects except the first one (index 0).
In this example there will be 6 vObjects I need to remove.
When I run the code above only every second vObject is removed for some reason.
I tried to debug the issue by putting an alert before the for-loop:
I also put an alert before voc.removeAt(i)...
...I find that only 3 objects exist, the other 3 are always null.
Any idea what might be causing this, or if there is a better way to achieve the above requirement?
Thanks!
Andrew
What is the correct way to remove all vObjects (except the first vObject) from a specific layer
on a CanvasViewer using javascript?
I'm finding that every second object I try to remove is null for some reason...
// This function removes all vObjects starting from index 1 from the 3rd layer of the CanvasViewer
function RemoveAll() {
var canvasViewer = $find("<%= photoLabel.CanvasViewer.ClientID %>");
var cv = canvasViewer.get_canvas();
var layers = canvasViewer.get_canvas().get_layers();
var voc = layers.get_item(2).get_vObjects();
for (var i = 1; i <= voc.get_count(); i++) {
voc.removeAt(i);
}
In one example, I have 7 objects on the 3rd layer. I want to remove all vObjects except the first one (index 0).
In this example there will be 6 vObjects I need to remove.
When I run the code above only every second vObject is removed for some reason.
I tried to debug the issue by putting an alert before the for-loop:
alert(voc.get_count()); // this displays 7 in my example
I also put an alert before voc.removeAt(i)...
alert(voc.get_item(i).get_index());
...I find that only 3 objects exist, the other 3 are always null.
Any idea what might be causing this, or if there is a better way to achieve the above requirement?
Thanks!
Andrew