Copy link to clipboard
Copied
Hello,
I am using canvas and have a MovieClip in my library called sliderBtn. I am trying to import it to the stage using the following code, but this only works if I actually put the element on the stage. I would like to be able to add it by using code, if possible. This seems like something pretty simple. Is it possible to import an MC from the library as in AS3?
sliderBtn = new lib.sliderBtn();
stage.addChild(sliderBtn);
sliderBtn.x = 200;
sliderBtn.y = 200;
If it's not used on any timeline you have to give it a linkage name by double-clicking the Linkage field in the library.
Copy link to clipboard
Copied
If it's not used on any timeline you have to give it a linkage name by double-clicking the Linkage field in the library.
Copy link to clipboard
Copied
I saw this thread indicating that while the linkage name is grayed out, you can still click it in the interface, but I don't see where... No fields in the properties panel are becoming active when I double click and enter a name.
CreateJS Linkage ID greyed out in Flash CC 2015/Canvas Document
Copy link to clipboard
Copied
Clay means the linkage column in the Library. Not inside the symbol properties. Double-click on the currently empty linkage column for that symbol, and type sliderBtn.
Copy link to clipboard
Copied
OMG. Thank you! This is not intuitive AT ALL.
Copy link to clipboard
Copied
Thanks for the "correct answer". I transferred it to Clay, because he gave the answer first, and his answer also gave the extra information about how if it's in the timeline you don't have to do the linkage name.
Copy link to clipboard
Copied
Yes, many thanks to both of you! In case it's helpful to someone else, here's a screen shot:
Copy link to clipboard
Copied
Something else that may matter, or not, I'm not sure! But you're adding the object to stage, and that isn't the same thing as the main timeline level. Here's a test:
alert(this==stage);
alert(this==exportRoot);
What I think of as being the main timeline is exportRoot and not stage.
As I say, it may not matter, but I would use:
this.addChild(sliderBtn);