JSFL How do I add an instance of a Library item to a different Library item?

StackOverflow https://stackoverflow.com/questions/14697744

  •  06-03-2022
  •  | 
  •  

Question

Lets say that I have a MovieClip with the name of "Face" inside the library. I also have a different MovieClip in the same library called "Eyes".

How can I make an instance of "Eyes" and add it to the "Face" MovieClip?

var mainFla = fl.documents[0];
var mainFlaTimeline = mainFla.getTimeline();
var mainFlaLibrary = mainFla.library;

Another way to say this is, imagine this is Flash. I would double click the Face library Item. Drag a copy of Eyes to the Face timeline and that's the job done. Face now contains an instance of Eyes.

timeline and layer and frame appear to have no "addItem" method as I may expect and all examples appear to assume I am adding an instance to the Stage of the document.

Was it helpful?

Solution

I cannot explain this concept well in words. I thought that addItem() was adding instances to the stage (as in the root, or as3 stage). However it appears when you enter edit mode on an item then mainFla.addItem(), that edited item gets the instance.

mainFlaLibrary.editItem("Face");
selectedIndex = mainFlaLibrary.findItemIndex("Eyes");
selectedItem = mainFlaLibrary.items[selectedIndex];
mainFla.addItem({x:0, y:0}, selectedItem); 

This is equivalent to double clicking the Face, and dragging an instance of Eyes into it from the library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top