Skip to content

Instantly share code, notes, and snippets.

@nowri
Created April 10, 2012 03:45
Show Gist options
  • Save nowri/2348193 to your computer and use it in GitHub Desktop.
Save nowri/2348193 to your computer and use it in GitHub Desktop.
ステージ上で選択したビットマップを同名のムービークリップに入れ替えるJSFL
/*
@author nowri.ka
@update 20120411
*/
var dom = fl.getDocumentDOM();
var _library = dom.library;
var ____ct;
var initialSelection;
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 init()
{
initialSelection = dom.selection.concat();
var _e = dom.selection[0];
dom.exitEditMode();
if(_e.libraryItem.name!=dom.selection[0].libraryItem.name)
{
____ct = dom.selection[0];
dom.enterEditMode("inPlace");
}
dom.selection = initialSelection;
for(var i = initialSelection.length-1; i>=0; i--)
{
var selectedObj = initialSelection[i];
if(selectedObj.instanceType=="bitmap")
{
swapBitmapToMC(selectedObj);
}
}
}
function swapBitmapToMC(elem)
{
var item = elem.libraryItem;
var path = item.name;
var name = getItemName(item);
var mcPath;
_library.addNewItem("movie clip", name);
mcPath = _library.getSelectedItems()[0].name;
_library.editItem();
_library.addItemToDocument({x:elem.width / 2, y:elem.height / 2}, path);
dom.selection[0].x =
dom.selection[0].y = 0;
dom.exitEditMode();
if(____ct)
{
_library.selectItem(____ct.libraryItem.name);
_library.editItem();
}
_library.selectItem(mcPath);
_library.addItemToDocument({x:elem.x + elem.width / 2, y:elem.y + elem.height / 2});
dom.selection[0].x = Math.round(dom.selection[0].x);
dom.selection[0].y = Math.round(dom.selection[0].y);
dom.selectNone();
dom.selection = [elem];
dom.deleteSelection();
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment