Skip to main content
Participant
April 23, 2019
Answered

For loop not working when added to function

  • April 23, 2019
  • 2 replies
  • 699 views

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?

    This topic has been closed for replies.
    Correct answer avid_body16B8

    I would do this.

    1- add to your first frame

    var root = this;

    then change this to root in your function.

    2 replies

    avid_body16B8
    avid_body16B8Correct answer
    Legend
    April 23, 2019

    I would do this.

    1- add to your first frame

    var root = this;

    then change this to root in your function.

    Participant
    April 24, 2019

    resdesign

    Worked like a charm. Thank you very much

    avid_body16B8
    Legend
    April 24, 2019

    My pleasure. good luck on your project.

    kglad
    Community Expert
    Community Expert
    April 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.

    Participant
    April 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