我们正在使用Adobe Flash Builder 4.6开发InDesign CS6扩展程序。 I got strange errors in a JavaScript Injection,所以我将JavaScript转换为Action Script并将其直接放入我的代码中。但错误仍然存在。
这是代码:
var pageItem:PageItem = (component as BaseComponent).pageItem;
var frame:Frame = new Frame(pageItem);
var itemIsHidden:Boolean = !pageItem.visible;
var tempFile:File;
var container:Rectangle = InDesign.app.activeDocument.rectangles.add(InDesign.app.activeDocument.activeLayer); // (2)
try {
pageItem.visible = true;
var prefix:String = "TMP_IMAGE_CONTAINER";
var bounds:Array = frame.convertToBounds();
Log.log("Container id = " + container.id);
Log.log("bounds = " + bounds);
Log.log("frame.ax = " + frame.ax + ", frame.ay = " + frame.ay);
container.name = prefix+container.id; // (3)
container.geometricBounds = bounds; // (1)
container.strokeWeight = 0;
container.strokeColor = InDesign.app.activeDocument.swatches.item("None");
container.fillColor = InDesign.app.activeDocument.swatches.item("None");
container.visible = true;
container.transparencySettings.blendingSettings.opacity = 100;
// create a duplicate of the pageItem in the tmp container
var copyItem:PageItem = pageItem.duplicate(InDesign.app.activeDocument.activeLayer);
copyItem.transparencySettings.blendingSettings.opacity = 100;
copyItem.locked = false;
container.geometricBounds = bounds;
container.move([frame.ax,frame.ay]); // (4)
copyItem.visible = true;
InDesign.app.select(copyItem);
InDesign.app.cut();
InDesign.app.select(container);
InDesign.app.pasteInto();
//InDesign.app.scriptArgs.setValue("container", prefix+container.id);
// [...]
} catch (e:Error) {
Log.log(e.toString());
Log.log(e.getStackTrace());
} finally {
if (container) {
container.remove();
}
pageItem.visible = !itemIsHidden;
}
开头的日志语句是为了确保变量是在此时定义的。但是,我一直以(看似)随机的方式得到错误:(1)
[INFO] [29:1786:739] [ImageExporter::export():65] Container id = 12818
[INFO] [29:1787:386] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [29:1787:931] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [29:1799:462] [ImageExporter::export():113] Error: Invalid value for set property 'geometricBounds'. Expected Array of 4 Units, but received null.
或(2)
Error: Cannot create page item. No valid parent found.
at flash.external::HostObject/__call()
at com.adobe.csawlib::CSHostObject/hostCall()
at com.adobe.indesign::Rectangles/add()
at ImageExporter/export()[...export/ImageExporter.as:58]
或(3)
[INFO] [14:843:201] [ImageExporter::export():65] Container id = 12818
[INFO] [14:843:202] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [14:843:202] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [14:843:239] [ImageExporter::export():114] Error: Invalid value for set property 'name'. Expected String, but received null.
或(4)
[INFO] [17:1025:895] [ImageExporter::export():65] Container id = 12818
[INFO] [17:1025:896] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [17:1025:896] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [17:1025:964] [ImageExporter::export():115] Error: Missing required parameter 'to' for method 'move'.
at flash.external::HostObject/__call()
at com.adobe.csawlib::CSHostObject/hostCall()
at com.adobe.indesign::Rectangle/move()
at ImageExporter/export()[.../export/ImageExporter.as:83]
导出同一对象时始终出现错误。我们检查了扩展内部的语法和InDesign中的对象,但一切似乎都没问题。
我是Action Script的新手,但我作为开发人员的常识告诉我,(1)bounds 是一个包含4个条目的数组(如日志消息中所述)和(2) )即使没有有效的父级,扩展也应该每次都在这里崩溃(我每次都使用相同的文件)。
可能是内存溢出错误(因为错误只出现在包含许多对象的InDesign-Files中)但我找不到增加它的选项。
注意:此类中使用的Rectangle是Extend script API中的一个类。