Creating multiple dynamic instances via new.lib HTML5 Canvas
I am rebuilding my old game built with AS2 for Adobe Animate canvas. Got stuck while duplicating the objects. Found this thread from JoãoCésar using new lib, and everything is fine but I would like to create multiple instances form my library item 'bug' (has linkage 'bug' as well). Pardon my code, but I would like to be something like this:
var that = this;
this.buttonAdd.addEventListener("click", addFromLibrary);
function addFromLibrary(e) {
for (var i = 0; i < 5; i++) {
var ["bug" + i] = new lib.bug();
["bug" + i].x = 10 * i;
["bug" + i].y = 10 * i;
that.addChild["bug" + i];
}
}... where I expect all 5 flying bugs on stage. Obviously it doesn't work with dynamic variables. As I understand bracket notation should be used over eval in Animate javascript, but not sure how exactly should I use it. As furhter more I would like to access these created bugs for collision event as well. Many thanks!
