A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Affecting multiple MCs with a for loop?

  1. #1
    Member
    Join Date
    Jan 2001
    Posts
    54

    Unhappy Affecting multiple MCs with a for loop?

    Let's say I have ten widgets that have ten items that need to be turned off. What am I doing wrong here?

    Code:
    for(i=1;i<=10;i++){
    	var tempWidget = ["widget0" + i];
    	trace(tempWidget);
    	tempWidget.item._visible=false;
    }
    The trace returns the correct value yet the loop doesn't turn the ten items off. Why?

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    for (i=1; i<=10; i++) {
    	var tempWidget=this["widget0"+i];
    	trace(tempWidget);
    	tempWidget.item._visible=false;
    }

  3. #3
    Member
    Join Date
    Jan 2001
    Posts
    54
    Excellent! Why is the "this" required though? Is it like saying "Hey, now tempWidget is going to be called this equasion I define over here"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center