Highlighted

For loop not working when added to function

Community Beginner ,
Apr 23, 2019

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?

Adobe Community Professional
Correct answer by resdesign | Adobe Community Professional

I would do this.

1- add to your first frame

var root = this;

then change this to root in your function.

Views

373

Likes

Translate

Translate

Report

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

For loop not working when added to function

Community Beginner ,
Apr 23, 2019

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?

Adobe Community Professional
Correct answer by resdesign | Adobe Community Professional

I would do this.

1- add to your first frame

var root = this;

then change this to root in your function.

Views

374

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 23, 2019 0
Adobe Community Professional ,
Apr 23, 2019

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2019 0
Community Beginner ,
Apr 24, 2019

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 24, 2019 0
Adobe Community Professional ,
Apr 23, 2019

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2019 1
Community Beginner ,
Apr 24, 2019

Copy link to clipboard

Copied

resdesign

Worked like a charm. Thank you very much

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 24, 2019 1
Adobe Community Professional ,
Apr 24, 2019

Copy link to clipboard

Copied

My pleasure. good luck on your project.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 24, 2019 0