Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davestewart/5212922 to your computer and use it in GitHub Desktop.
Save davestewart/5212922 to your computer and use it in GitHub Desktop.
Converts selected stage elements to library items, including naming and selecting them in the library. Supports shape objects with multiple members.
/**
* Convert selected elements to library items
* @author Dave Stewart
* @url www.xjsfl.com
*/
// variables
var dom = document, timeline, element, names = [], name;
// create a new movieclip in which to do our conversion
dom.convertToSymbol('graphic', '__temp__', 'center');
dom.enterEditMode('inPlace');
dom.distributeToLayers();
timeline = document.getTimeline();
// loop through the layers, converting elements and propting for names
for (var i = 0; i < timeline.layers.length; i++)
{
element = timeline.layers[i].frames[0].elements[0];
if(element)
{
dom.selectNone();
dom.selection = [element];
name = prompt('Name this object, or Cancel to skip', 'Symbol ' + (names.length + 1));
if(name)
{
names.push(name)
dom.convertToSymbol('movie clip', name, 'center');
}
}
}
// return to the parent timeline
dom.exitEditMode();
dom.breakApart();
dom.library.deleteItem('__temp__');
// name elements after their library items, and select items in library
dom.library.selectNone();
for each(element in dom.selection)
{
if(element.elementType == 'instance')
{
name = element.libraryItem.name;
dom.library.selectItem(name, false);
element.name = name.replace(/ /g, '_').toLowerCase();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment