【问题标题】:JSFL: selecting items returned by fl.findObjectInDocByType()JSFL:选择 fl.findObjectInDocByType() 返回的项目
【发布时间】:2012-01-09 03:23:45
【问题描述】:

我似乎无法将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, 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});
    }
}

结果:Error:doc.getTimeline().theLayer has no properties

【问题讨论】:

    标签: jsfl


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

      事实证明,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});
          }
      }
      

      【讨论】:

        【解决方案3】:

        我最近遇到了类似的问题,显然所有关于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();
        

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-11-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-09-05
          • 1970-01-01
          相关资源
          最近更新 更多