I have the following (useless) code, which should select each text element in the current Flash document:
fl.outputPanel.clear();
var textFieldArray = fl.findObjectInDocByType("text", fl.getDocumentDOM());
fl.trace(textFieldArray.length);
for (var i=0; i < textFieldArray.length; i ++){
fl.selectElement(textFieldArray[i]);
}
Surprisingly, this results in an error
At line 232 of file "ObjectFindAndSelect.jsfl": 'enterEditMode' requires a selection.
Looking into the file, the code for the selectElement function is
flash.selectElement = function(elementData, editSymbol)
{
if (elementData.parent != undefined)
{
// go up one level
flash.selectElement(elementData.parent, true);
}
else
{
FlashUtils_debugString("flash.selectElement function: element is on the main timeline");
}
// select the layer, keyframe and element in the symbol instance
var layerIndex = FlashUtils_getIndexOfObject(elementData.timeline.layers, elementData.layer);
var frameIndex = FlashUtils_getIndexOfObject(elementData.layer.frames, elementData.keyframe);
if ((layerIndex >= 0) && (frameIndex >= 0))
{
// go to obj keyframe
elementData.timeline.setSelectedLayers(layerIndex);
elementData.timeline.setSelectedFrames(frameIndex, frameIndex);
// clear all selections in keyframe
fl.getDocumentDOM().selectNone();
// select the obj
elementData.obj.selected = true;
if (editSymbol)
{
// switch to editing the symbol item associated with instance
document.enterEditMode('inPlace');
}
}
else
{
FlashUtils_debugString("flash.selectElement function: parent: failed to get valid layerIndex: " + layerIndex + " or frameIndex: " + frameIndex);
}
}
It seems clear to me that this should work; the selected property of the object is set to true immediately before the call to document.enterEditMode. Tinkering with this function, I tried adding a line immediately after the elementData.obj.selected = true; line, tracing whether or not the selection was empty. The code looked like the following:
elementData.obj.selected = true;
fl.trace(fl.getDocumentDOM().selection.length);
The output of this code was 0.
Why is this error occurring? Is there anything I can do to fix it?
I guess you can only select symbol instances using document.selection. And you have to use fl.getDocumentDOM().selection = [array of symbol elements]