PDA

View Full Version : Find instancename inside libraryItem


Boersnoes
05-04-2006, 09:46 AM
As described in http://www.actionscript.org/forums/showthread.php3?s=&threadid=29696 I made this script that walks through all the scenes, layers, frames and objects 'till it finds an object with the instance name you've given.
Then it returns either true and the number of the scene, layer, frame and item or false (if not found)
Now I want to be able to use this script not only on the main stage, but also inside mc's.
I already wrote the script to find the library path of an item on stage and then open this library item.

Any hints would be greatly appreciated

Boersnoes
05-05-2006, 10:11 AM
Solved it myself. Sollution was in the fact that fl.getDocumentDOM().library.items[] doesn't just return an instance of Item (like the documentation says), but an instance of the subset SymbolItem. This has a property timeline (notice the absence of the "s") and from there on it was a piece of cake...

function init(itemName, libIndex, layer, frame){
var layerCounter=Number(layer);
alert(fl.getDocumentDOM().library.items[libIndex]);
while(layerCounter<fl.getDocumentDOM().library.items[libIndex].timeline.layers.length){
var frameCounter=Number(frame);
while(frameCounter<fl.getDocumentDOM().library.items[libIndex].timeline.layers[layerCounter].frames.length){
var elementCounter = 0;
while(elementCounter<fl.getDocumentDOM().library.items[libIndex].timeline.layers[layerCounter].frames[frameCounter].elements.length){
if(fl.getDocumentDOM().library.items[libIndex].timeline.layers[layerCounter].frames[frameCounter].elements[elementCounter].name == itemName){
alert([true, layerCounter, frameCounter, elementCounter]);
return([true, 0, layerCounter, frameCounter, elementCounter]);
}
elementCounter++;
}
frameCounter++;
}
layerCounter++;
}
alert(false);
return(false);
}
init("mmSectionBtn1Label_mc", 97,"","");