0

我正在尝试用较新的影片剪辑替换过时的影片剪辑。

为此,我使用 JSFL 来定位旧的影片剪辑,保存参考,然后在其位置添加新版本。

我查看了 addItem addItemToDocument 并且他们成功添加了剪辑,但我不确定如何将其添加到电影剪辑的旧实例所在的特定图层和帧。

哈尔普斯

4

1 回答 1

0

用新的movieclip 的实例替换旧movieclip 的所有实例可能是一个更简单的解决方案。通过解析 Flash 文档的时间线,可以找到旧影片剪辑的所有实例。这是一些代码:

var _doc = (fl.getDocumentDOM() ? fl.getDocumentDOM() : fl.createDocument());
var _lib = _doc.library;
fl.outputPanel.clear();
ReplaceItemWithItem('Game Layouts/card holder', 'Game Layouts/card holder new');
function ReplaceItemWithItem(oldmcname, newmcname)
{
  var item1 = GetItem(oldmcname);
  var item2 = GetItem(newmcname);
  if (!item1) return false;
  if (!item2) return false;
  if (oldmcname == newmcname)
    return true;
  return ReplaceAllItems(item1, item2);
}
function ReplaceAllItems(item1, item2)
{
  var timelines = _doc.timelines;
  var i, l = timelines.length;
  var items = _lib.items;
  var changed = false;
// Main timelines
  for (i = 0; i < l; i++)
  {
    var timeline = timelines[i];
    changed |= ReplaceItems(timeline, item1, item2);
  }
// Timelines in library items
  for (i = 0, l = items.length; i < l; i++)
  {
    var item = items[i];
    switch (item.itemType)
    {
    case "movie clip":
    case "graphic":
    case "button":
      changed |= ReplaceItems(item.timeline, item1, item2);
      break;
    }
  }
  return changed;
}
function ReplaceItems(timeline, item1, item2)
{
  var changed = false;
  if (timeline && item1 && item2)
  {
    var layers = timeline.layers;
    var lay, layl = layers.length;
    for (lay = 0; lay < layl; lay++)
    {
      var layer = layers[lay];
      var frames = layer.frames;
      var fr, frl = frames.length;
      for (fr = 0; fr < frl; fr++)
      {
        var frame = frames[fr];
        if (frame && frame.startFrame == fr)
        {
          var elements = frame.elements;
          var e, el = elements.length;
          for (e = 0; e < el; e++)
          {
            var elem = elements[e];
            if (elem && elem.elementType == "instance")  // Elements can be empty
            {
              var item = elem.libraryItem;
              if (item.name == item1.name)
              {
                elem.libraryItem = item2;
                changed = true;
              }
            }
          }
        }
      }
    }
  }
  return changed;
}
function GetItem(itemname)
{
  if (!_lib.selectItem(itemname))
  {
    alert("'" + name + "' does not exist in the library!");
    return null;
  }
  return _lib.getSelectedItems()[0];
}

希望这可以帮助!

于 2013-10-08T21:56:05.533 回答