Created
April 9, 2012 09:47
-
-
Save nowri/2342585 to your computer and use it in GitHub Desktop.
jsfl file lazySymbolConverter for Flash CS5
This file contains 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
/* | |
lazySymbolConverter for CS5 | |
@see http://f-site.org/articles/2008/12/14224253.html | |
@update 20120409 | |
*/ | |
// original copyrights | |
/*------------------------ | |
lazySymbolConverter ver 0.8. | |
written by Satoshi Onoda | |
http://emotional-box.com | |
This command is distributed with Creative Commons Attribution 3.0. | |
You are free to share, remix this extension but don't remove the original copyrights. | |
http://creativecommons.org/licenses/by/3.0/ | |
------------------------*/ | |
var dom = fl.getDocumentDOM(); | |
var library = dom.library; | |
var timeline = dom.getTimeline(); | |
// | |
function checkElementType(element) { | |
isHasError = element.itemType != 'bitmap'; | |
} | |
// | |
function getItemName(element){ | |
var itemName = element.name; | |
re1 = new RegExp("\\..*", "i"); | |
itemName = itemName.replace(re1, ""); | |
// | |
re2 = new RegExp(".*/") | |
itemName = itemName.replace(re2, ""); | |
return itemName; | |
} | |
// | |
function checkExistence(itemName) { | |
isHasError = library.itemExists(itemName); | |
} | |
// | |
function convertToSymbol(item, itemName) { | |
library.addNewItem('movie clip', itemName); | |
timeline.addNewLayer("workLayer"); | |
dom.addItem({x:0, y:0}, library.items[library.findItemIndex(itemName)]); | |
var addedItem = dom.selection[0]; | |
// addedItem.x = item.x; | |
// addedItem.y = item.y; | |
addedItem.name = itemName; | |
} | |
// | |
function replaceObject(item, itemName) { | |
dom.enterEditMode('inPlace'); | |
var bitmapItem = item; | |
dom.addItem({x:0, y:0}, bitmapItem); | |
var addedItem = dom.selection[0]; | |
addedItem.x = 0; | |
addedItem.y = 0; | |
dom.exitEditMode(); | |
timeline.deleteLayer(timeline.findLayerIndex("workLayer")[0]); | |
// | |
// dom.selectNone(); | |
// dom.selection = [item]; | |
// dom.deleteSelection(); | |
} | |
// | |
var initialSelection = new Array(); | |
var sels = dom.library.getSelectedItems(); | |
for(var i = 0; i < sels.length; i++) { | |
initialSelection.push(sels[i]); | |
} | |
// | |
for(var i = 0; i < initialSelection.length; i++) { | |
isHasError = false; | |
var selectedObj = initialSelection[i]; | |
var itemName = ''; | |
// | |
!isHasError ? checkElementType(selectedObj) : ''; | |
!isHasError ? itemName = getItemName(selectedObj) : ''; | |
!isHasError ? checkExistence(itemName) : ''; | |
!isHasError ? convertToSymbol(selectedObj, itemName) : ''; | |
!isHasError ? replaceObject(selectedObj, itemName) : '' ; | |
// | |
//isHasError ? alert('something wrong') : ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment