我有以下(无用的)代码,它应该选择当前Flash文档中的每个文本元素:
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]);
}
令人惊讶的是,这会导致错误
在文件的第232行&#34; ObjectFindAndSelect.jsfl&#34;:&#39; enterEditMode&#39;需要选择。
查看文件,selectElement
函数的代码是
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);
}
}
我觉得这应该有用;在调用selected
之前,对象的document.enterEditMode
属性设置为true。修改此功能,我尝试在elementData.obj.selected = true;
行之后立即添加一行,跟踪选择是否为空。代码如下所示:
elementData.obj.selected = true;
fl.trace(fl.getDocumentDOM().selection.length);
此代码的输出为0
。
为什么会出现此错误?我能做些什么来解决它吗?
答案 0 :(得分:0)
我猜你只能使用document.selection选择符号实例。你必须使用fl.getDocumentDOM()。selection = [symbol of elements elements]