I want to swap a bitmap in symbol with another bitmap,and I found the the function
swapElement
This is what I have tried
var elements = item.timeline.layers[0].frames[0].elements;//item is the symbol
for (var j = 0; j < elements.length; j++) {
var el = elements[j];
if (el.instanceType == "bitmap") {
el.selected = true;//this line not work, so I want a way to make the element selected
dom.swapElement(targetName);//targetName is another bitmap name that I wanted
}
}
Setting selected to true of an element, will only select the element if the element is on screen (and the layer is unlocked and visible). So before selected is set to true library.editItem(item.name) should be called. If the element is in frame x, frame x has to be made the current frame with document.getTimeline().setSelectedFrames(parseInt(x), parseInt(x) + 1, true). (I use parseInt(x) as a cast because of a bug in setSelectedFrames). To be sure the element is the only element that is selected document.selectNone() should be called before setting selected to true.
Every instance has a libraryItem so maybe replacing the libraryItem is easier. The code here can be adapted for a more selective replace.