This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
Andy79  
#1 Posted : Sunday, October 7, 2012 8:05:27 PM(UTC)
Andy79

Rank: Member

Groups: Guest
Joined: 7/31/2012(UTC)
Posts: 14

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
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...

Code:


// 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:

Code:

alert(voc.get_count()); // this displays 7 in my example


I also put an alert before voc.removeAt(i)...

Code:

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
p.shirykalova  
#2 Posted : Tuesday, October 9, 2012 1:44:03 AM(UTC)
p.shirykalova

Rank: Advanced Member

Groups: Guest
Joined: 7/13/2011(UTC)
Posts: 286

Thanks: 6 times
Was thanked: 31 time(s) in 31 post(s)
Hi Andrew!

Sorry for my late reply.
I discussed your issue with our developers. They provided me with the code example which might be helpful:
Code:
$(".psdEditor button.delete").live('click', function () {
   if (!confirm(self._confirmDeleteText)) return false;
   var vObjects = ($(this).closest('#imageInputList').size() > 0 ? self.getCurrentLayerImage() : self.getCurrentLayerText()).get_vObjects();
   var id = $(this).closest('li').attr('id');
   for (var k = 0; k < vObjects.get_count(); k++) {
    var item = vObjects.get_item(k);
    if (item.get_uniqueId() == id) {
     vObjects.removeAt(vObjects.indexOf(item));
     break;
    };
   }
   self._canvas.set_currentVObjectIndex(-1);
   self._canvas.redraw();
   self._onZoneChange();
   $('.psdEditor').trigger('userImageChanged', []);
   return false;
  });

They say the attention should be paid on this line:
Code:
vObjects.removeAt(vObjects.indexOf(item));

This is the correct way to delete vObjects.
Best regards,
Pauline Shirykalova
Aurigma Technical Support
Andy79  
#3 Posted : Tuesday, October 9, 2012 3:42:50 PM(UTC)
Andy79

Rank: Member

Groups: Guest
Joined: 7/31/2012(UTC)
Posts: 14

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Thanks Pauline,

The code provided is not what I require.
Please ask your developers to provide an example of removing vObjects from a specific CanvasViewer layer.

I am using the .removeAt method already and notice that not all vObjects are being removed. I would like your developers to clarify whether my implementation is incorrect or whether this is a bug with the CanvasViewer.

Thanks,
Andrew
p.shirykalova  
#4 Posted : Thursday, October 11, 2012 1:13:07 AM(UTC)
p.shirykalova

Rank: Advanced Member

Groups: Guest
Joined: 7/13/2011(UTC)
Posts: 286

Thanks: 6 times
Was thanked: 31 time(s) in 31 post(s)
Hi Andy,

You don't consider the fact that the index of the objects standing after the one you delete is decreased by 1. Please try the following code:
Code:
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();
 
 while(voc.get_count() > 1)
{
    voc.removeAt(voc.get_count() - 1);
}

cv.set_currentVObjectIndex(-1);
cv.redraw();
}

Best regards,
Pauline Shirykalova
Aurigma Technical Support
thanks 1 user thanked p.shirykalova for this useful post.
Andy79 on 10/15/2012(UTC)
Andy79  
#5 Posted : Monday, October 15, 2012 6:08:44 PM(UTC)
Andy79

Rank: Member

Groups: Guest
Joined: 7/31/2012(UTC)
Posts: 14

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Thanks very much. The code worked perfectly.
thanks 1 user thanked Andy79 for this useful post.
p.shirykalova on 10/15/2012(UTC)
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.