Copy link to clipboard
Copied
Hi all!!!
I have more than 15 movieClips on stage with instance name icon1, icon2, icon3 ..... and I need to change their scaleX and scaleY from a variable in
function onMouseMove (evt) {
var sizeIconXY = (scaleNumerica / 10000)
this.map.icon1.scaleX = sizeIconXY // statement 1
this.map.icon1.scaleY = sizeIconXY // statement 2
}
Is it possible to have a function that unifies the scaleX / scaleY (sentence 1 and 2) and not have to repeat the sentence in all 15 (icon1, icon2, icon3 ...), is it possible?
I was looking with:
document.getElementById ("icon *")
but I can't solve it.
From already thank you very much.
Copy link to clipboard
Copied
Hi,
Yes, it is posiible 🙂
Could you specify a little bit what you try to achieve?
What kind of scripting you use: JSFL (authoring mode), AS or JS?
A basic advice: you can store all your references in array during creation and later you can itarate through this collection:
var iconCollection = [];
/*
You need to add all references, e.g. icon1, icon2, icon3 ...
to iconCollection array in order to manipulate them with a loop
*/
function onMouseMove (evt) {
var sizeIconXY = (scaleNumerica / 10000);
for( var i = 0; i < iconCollection.length; i++ ){
var theIcon = iconCollection[ i ];
theIcon.scaleX = sizeIconXY; // statement 1
theIcon.scaleY = sizeIconXY; // statement 2
}
}
Copy link to clipboard
Copied
Thanks for your answer!!!
When adding and removing movieClips from the stage, the ideal is to detect the instance of the movieClips that start with "icon" and all change the scaleX / scaleY, it is possible with:
document.getElementById ("icon *")
thanks
Copy link to clipboard
Copied
Animate HTML5 Canvas objects are not browser DOM objects. Canvas projects use the CreateJS library for everything. There is no such thing as getElementById() in CreateJS.
To find every clip on the stage with a name that starts with "icon", you'd have to do something like this:
var i, clip;
for (i = 0; i < this.numChildren; i++) {
clip = this.children[i];
if (clip.name.indexOf("icon") === 0) {
console.log(clip.name);
}
}