Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

For loop not working when added to function

Community Beginner ,
Apr 23, 2019 Apr 23, 2019

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?

610
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 23, 2019 Apr 23, 2019

I would do this.

1- add to your first frame

var root = this;

then change this to root in your function.

Translate
Community Expert ,
Apr 23, 2019 Apr 23, 2019

'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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2019 Apr 24, 2019

Hi,

Looks like you were right. I did the 'root' thing from the other response and it has worked.

Thanks for your help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 23, 2019 Apr 23, 2019

I would do this.

1- add to your first frame

var root = this;

then change this to root in your function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2019 Apr 24, 2019

resdesign​

Worked like a charm. Thank you very much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 24, 2019 Apr 24, 2019
LATEST

My pleasure. good luck on your project.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines