JSFL:选择 fl.findObjectInDocByType() 返回的项目
我似乎无法将 fl.findObjectInDocByType()
返回的信息与 fl.getDocumentDOM().selection
一起使用。
我想使用 document.setTextRectangle 来调整使用 fl.findObjectInDocByType() 生成的数组中的某些文本字段的大小。
我可以轻松访问所有 textObject 属性,但由于 document.setTextRectangle
需要当前选择,所以我不知所措。
文档中用于设置选择的示例是:
fl.getDocumentDOM().selection = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
fl.findObjectInDocByType() 返回具有以下属性的对象数组: (object.timeline
, object.layer< /code>,
object.frame
, object.parent
)
但这些是对象,并且没有所需的数组索引号属性fl.getDocumentDOM().selection=
...
var doc = fl.getDocumentDOM();
var textFieldArray = fl.findObjectInDocByType("text", doc);
for (var i=0; i < textFieldArray.length; i ++){
fnResizeTheTextField(textFieldArray[i]);
}
function fnResizeTheTextField(theTextField){
//force current selection to be theTextField
//doc.selection MUST be an array, so assign theTextField to an array...
var selectArray = new Array();
selectArray[0] = theTextField.obj;
var theTimeline =theTextField.timeline;
var theLayer =theTextField.layer;
var theFrame =theTextField.frame;
doc.currentTimeline =theTextField.timeline;
doc.selection = doc.getTimeline().theLayer.theFrame.selectArray;//error
//resize the text rectangle
doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
}
}
结果:错误:doc.getTimeline().theLayer 没有属性
I can't seem to use the info returned by fl.findObjectInDocByType()
with fl.getDocumentDOM().selection
.
I want to use document.setTextRectangle
to re-size some text fields from an array generated using fl.findObjectInDocByType()
.
I can easily access all the textObject properties but since document.setTextRectangle
requires a current selection, I am at a loss.
The example in the documentaion for setting selection is:
fl.getDocumentDOM().selection = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
fl.findObjectInDocByType()
returns an array of objects with the attributes: (object.timeline
, object.layer
, object.frame
, object.parent
)
But these are objects, and don't have a property for array index numbers required by fl.getDocumentDOM().selection=
...
var doc = fl.getDocumentDOM();
var textFieldArray = fl.findObjectInDocByType("text", doc);
for (var i=0; i < textFieldArray.length; i ++){
fnResizeTheTextField(textFieldArray[i]);
}
function fnResizeTheTextField(theTextField){
//force current selection to be theTextField
//doc.selection MUST be an array, so assign theTextField to an array...
var selectArray = new Array();
selectArray[0] = theTextField.obj;
var theTimeline =theTextField.timeline;
var theLayer =theTextField.layer;
var theFrame =theTextField.frame;
doc.currentTimeline =theTextField.timeline;
doc.selection = doc.getTimeline().theLayer.theFrame.selectArray;//error
//resize the text rectangle
doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
}
}
Result: Error:doc.getTimeline().theLayer has no properties
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明,ObjectFindAndSelect.jsfl 脚本已经包含专门用于此目的的函数:fl.selectElement()。更加优雅:
It turns out, the ObjectFindAndSelect.jsfl script already contains a function specifically for this: fl.selectElement(). Much more elegant:
我找到了答案。为了选择文档级操作的任何内容,您还必须使 Flash 聚焦于该对象的关键帧。
因此,如果我循环遍历由 fl.findObjectInDocByType() 创建的对象数组,我会使用此代码使 flash 正确聚焦在对象上:
但这可能不适用于嵌套在符号内的对象。
I found the answer. In order to select anything for a document level operation, you have to also make flash focus on the keyframe of that object.
so, if I loop through an array of objects created by fl.findObjectInDocByType(), I use this code to make flash focus on the object correctly:
this may not work on objects nested inside a symbol however.
我最近遇到了类似的问题,显然所有关于
setTextRectangle()
的谷歌结果都将我们引导到这里。令人难以置信的是,jsfl 的文档记录如此之差:)如果您需要在不在舞台上的库项目中使用
setTextRectangle()
,则需要先打开该项目进行编辑。这是解决我的问题的代码:
如果您有更好的工作解决方案,请发布。我希望它可以节省某人的时间。祝你好运!
I had a similar issue recently, and apparently all google results about
setTextRectangle()
direct us here. It's unbelievable how poorly documented jsfl is :)If you need to use
setTextRectangle()
inside an library item that is not on stage, you need to open for edit the item first.Here's the code that solved my problem:
If you have a better working solution, please post. I hope it saves somebody's time. Good luck!