version flash cs5
ok so i know the general code to rename all selected library items
var items = fl.getDocumentDOM().library.getSelectedItems();
for (var i=0; i<items.length; i++){
var item = items[i];
item.name = "ABC_"+item.name;
}
but this isn't good enough if the library items are in folders... because item.name returns the full path, but item.name sets the name. o.O as someone else points out here, http://forums.adobe.com/message/107718
- so when i try to rename Level1 to be ABC_Level1
- if Level1's folder path is LIBRARY/FolderA/FolderB/Level1
- i get this instead
- ABC_FolderA-FolderB-Level1
i could probably code some sort of string parser something like this,
item.name = "ABC_"+item.name.substr(item.name.lastIndexOf("-"), 99)
but that is really ugly and would not work if library items contained "-" already. "Level-1" for example
so i guess what I'm hoping for is a different way to access the name that returns just the name and not the path
It's tricky because when you get the name it's the full path, but when you set the name, it's just the item name (and not the path). You have to separate the name and the folder before concatenating. So, there isn't a "clean" way to do it, though writing a function might make it more readable:
Then set the name of the item thusly: