Copy link to clipboard
Copied
Hi,
New here hopefully, this is in the right place.
I have several pop-ups on the stage called pop1-10. I need them to be hidden at run time.
When I try and achieve this using a for loop, it works fine.
for(i=1;this['pop'+i]!=undefined;i++)
{
this['pop'+i].visible=false;
console.log('pop'+i+' hidden');
}
When I try and put this in a function to use later on. It doesn't identify any of the 'pop' objects and leaves them visible.
function hPop()
{
for(var i=1;this['pop'+i]!=undefined;i++)
{
this['pop'+i].visible=false;
console.log('pop'+i+' hidden');
}
}
hPop();
Any ideas as to what I'm doing wrong?
1 Correct answer
I would do this.
1- add to your first frame
var root = this;
then change this to root in your function.
Copy link to clipboard
Copied
'this' is not the parent of your pop-ups when/how hPop() is called, or you're calling hPop() when your pop-ups are not what you think they are. to debug use the trace() function.
Copy link to clipboard
Copied
Hi,
Looks like you were right. I did the 'root' thing from the other response and it has worked.
Thanks for your help
Copy link to clipboard
Copied
I would do this.
1- add to your first frame
var root = this;
then change this to root in your function.
Copy link to clipboard
Copied
resdesign​
Worked like a charm. Thank you very much
Copy link to clipboard
Copied
My pleasure. good luck on your project.

