Most Fireworks extensions act on the currently selected elements. Users will expect the same elements to be selected after the command is done, but the selection typically changes during the execution of the command.
To maintain the selection, all you have to do is copy the current selection into an array and then restore it at the end of the command.
// make a copy of the current selection by concatenating it
// with an empty array
var originalSelection = [].concat(fw.selection);
for (var i = 0, len = originalSelection.length; i < len; i++) {
// change the selection as needed
}
// restore the original copy of the selection
fw.selection = originalSelection;
Note that some Fireworks API methods, such as
dom.removeTransformation(), will cause the reference
to the selected element to go stale, so the element will not be
selected at the end of the command. You might also get an
error. To avoid this, reference the affected element again in
the
originalSelection array at the end of the for loop,
e.g.:
originalSelection[i] = fw.selection[0];
+