Instantiate the same movie clip more than once from the library using HTML5 JS
Hi Animate Community,
I would like to instantiate the same movie clip more than once from the library. In other words, I would like to be able to get more than one instance of the same movie clip from the library using the same button to get each. I have successfully figured out how to instantiate one clip and position it on the stage from a button click on a nested movie clip. Here's my code on the nested clip:
this.starFrontLg_btn.addEventListener("click", getStarFrontLg.bind(this));
function getStarFrontLg()
{
exportRoot.positionStarFrontLg();
}
And here's my code on the main timeline that shows how I got one clip from the library. I would like to be able to rename the first clip, then get another using the same button. So far, if I click on the button a second time, it still acts on the first clip. Obviously, I must be able to name each clip as it's instantiated and then somehow reset the button to get another clip rather than reposition the first one. Any help with this will be greatly appreciated.
Zaffer
let starFrontLg = new lib.starFrontLg();
let currentFlower;
let currentPetals;
var colorFilter_yellow = new createjs.ColorFilter(1, 1, 1, 1, 79, 79, -255, 0);
var colorFilter_orange = new createjs.ColorFilter(1, 1, 1, 1, 55, -51, -255, 0);
var currentBounds;
this.positionStarFrontLg = function()
{
this.addChild(starFrontLg);
starFrontLg.x = 200;
starFrontLg.y = 200;
};
starFrontLg.addEventListener("click", clickSomeFlower);
function clickSomeFlower(e)
{
currentFlower = e.currentTarget;
currentPetals = currentFlower.petals_mc;
currentBounds = currentPetals.nominalBounds;
}
this.yellow_btn.addEventListener("click", changeColorYellow.bind(this));
function changeColorYellow()
{
currentPetals.filters = [ colorFilter_yellow ];
currentPetals.cache(-currentBounds.width * 0.5, -currentBounds.height * 0.5, currentBounds.width, currentBounds.height);
};
P.S. Special thanks to JoãoCésar for help with using the Advanced panel settings to color a clip, https://community.adobe.com/t5/animate-discussions/javascript-code-for-animate-color-effects-gt-advanced-settings/m-p/12763489#M351600 and for this info on how to to call a function from a nested clip https://community.adobe.com/t5/animate-discussions/how-to-call-a-function-on-the-main-timeline-from-a-nested-timeline/td-p/12759954 and for this tip on how to instantiate a movie clip with HTML5. https://community.adobe.com/t5/animate-discussions/create-movie-clip-objects-dynamically-and-add-them-to-the-stage-with-javascript-in-html5-in-animate/td-p/11212808 Thanks João
