Created
March 21, 2013 13:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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