A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How to Condense Multiple

  1. #1
    Junior Member
    Join Date
    May 2002
    Posts
    22
    Hi,

    Is there any way to use multiple variables in a if statement. For instance instead of individually typing :

    if(colour1 == "yellow"){
    'do whatever'
    }
    if(colour2 == "yellow"){
    'do whatever'
    }

    Say you had 100 colours and all you want to find out is if any of them equal yellow or red is there anyway to do so something like below:

    if(colour1 or colour2 or colour3 == "yellow" or "red"){
    'do whatever'
    }

    I'm relatively new at code, just trying to make it tidier and more efficient.

    Any help would be Appreciated.

  2. #2
    Welcome to flavour country
    Join Date
    Sep 2000
    Posts
    662
    I would use a loop for something like this.

    Example:

    Code:
    for(i=1;i<=100;i++){
    if(this["color"+i] == "yellow" || this["color"+i] == "red"){
    trace("do stuff");
    break;
    }
    }
    Hope that helps.

  3. #3
    Junior Member
    Join Date
    May 2002
    Posts
    22
    Thanks for the reply Wiz,

    Sounds like that might be the go, a loop will cut the amount of code down.

    Thanks

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