JSFL:选择 fl.findObjectInDocByType() 返回的项目

发布于 2024-12-18 18:28:07 字数 1619 浏览 0 评论 0原文

我似乎无法将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧梦荧光笔 2024-12-25 18:28:07

事实证明,ObjectFindAndSelect.jsfl 脚本已经包含专门用于此目的的函数:fl.selectElement()。更加优雅:

var doc = fl.getDocumentDOM();
// generate an array of elements of type "text"
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
        fl.selectElement(theTextField,false);//enter 'edit mode' =false...
        //resize the text rectangle
        doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
    }
}

It turns out, the ObjectFindAndSelect.jsfl script already contains a function specifically for this: fl.selectElement(). Much more elegant:

var doc = fl.getDocumentDOM();
// generate an array of elements of type "text"
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
        fl.selectElement(theTextField,false);//enter 'edit mode' =false...
        //resize the text rectangle
        doc.setTextRectangle({left:0, top:0, right:1000, bottom:1000});
    }
}
梦回旧景 2024-12-25 18:28:07

我找到了答案。为了选择文档级操作的任何内容,您还必须使 Flash 聚焦于该对象的关键帧

因此,如果我循环遍历由 fl.findObjectInDocByType() 创建的对象数组,我会使用此代码使 flash 正确聚焦在对象上:

function fnMakeFlashLookAt(theObject){
        doc.currentTimeline =theObject.timeline;
        doc.getTimeline().currentLayer =theObject.layer;
        doc.getTimeline().currentFrame =theObject.frame;
    }

但这可能不适用于嵌套在符号内的对象。

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:

function fnMakeFlashLookAt(theObject){
        doc.currentTimeline =theObject.timeline;
        doc.getTimeline().currentLayer =theObject.layer;
        doc.getTimeline().currentFrame =theObject.frame;
    }

this may not work on objects nested inside a symbol however.

隔岸观火 2024-12-25 18:28:07

我最近遇到了类似的问题,显然所有关于 setTextRectangle() 的谷歌结果都将我们引导到这里。令人难以置信的是,jsfl 的文档记录如此之差:)

如果您需要在不在舞台上的库项目中使用 setTextRectangle(),则需要先打开该项目进行编辑。

这是解决我的问题的代码:

library.selectItem(libraryItemName);
doc.selection = [tf];//where tf is the reference to textfield we need to edit
doc.library.editItem(libraryItemName);  
doc.setTextRectangle({left:l, top:t, right:r, bottom:b});
doc.selectNone();

如果您有更好的工作解决方案,请发布。我希望它可以节省某人的时间。祝你好运!

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:

library.selectItem(libraryItemName);
doc.selection = [tf];//where tf is the reference to textfield we need to edit
doc.library.editItem(libraryItemName);  
doc.setTextRectangle({left:l, top:t, right:r, bottom:b});
doc.selectNone();

If you have a better working solution, please post. I hope it saves somebody's time. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文