A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: 150 x If ....else...else...else ?

  1. #1
    Member
    Join Date
    Aug 2005
    Posts
    51

    Question 150 x If ....else...else...else ?

    Hi,

    I have 150 sounds, one of which will play when randomly selected on
    button click.

    In pseudo code: On button click, if var ==1, play sound1
    else, if var==2, play sound2
    else, if var==3, play sound3
    etc etc to sound150

    Is all this really necessary? I'm sure it's not.

    Dips

    Also, can anyone direct me to simple descriptions of the main
    functions of programming. I'm thinking along the lines of principles that
    apply to all codes (if statements, loops etc) rather than language specific
    explanations. I'm learning from the coding help here but I feel I would
    have deeper understanding by learning the key basics that all programmers
    use.
    Last edited by diputs; 08-21-2009 at 12:08 PM.

  2. #2
    Senior Member
    Join Date
    Jun 2009
    Posts
    171
    Look into "for" statements.

    I'm not great with them, but that's definitely what you'll want to use.

  3. #3
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Use a switch statement

    PHP Code:
    switch(var)
    {
        case 
    1:
           
    play sound 1;
           break;
        case 
    2:
           
    play sound 2;
           break;
        case 
    3:
            
    play sound 3;
           break;
        default:
            
    play sound 160;

    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Is all this really necessary? I'm sure it's not.
    You're right
    This is a typical case where if statements (and for loops or switch etc.) are really not needed. All you need is one line:

    play "sound"+var

    gparis

  5. #5
    Member
    Join Date
    Aug 2005
    Posts
    51
    Wow! Holy moly!

    Quote Originally Posted by gparis View Post
    You're right
    This is a typical case where if statements (and for loops or switch etc.) are really not needed. All you need is one line:

    play "sound"+var

    gparis
    Now that is what I call elegant! (Sigh) I have so much to learn.

    Thanks Genevieve, and thanks for your earlier help...which I'm still trying to digest.

    dips

  6. #6
    Member
    Join Date
    Aug 2005
    Posts
    51
    Genevieve,

    I think there's something missing.

    I tried your suggestion (just cut and paste) and it returned a
    syntax error.

    Fingers still crossed here.

    dips

  7. #7
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    yes i replied with your pseudo-code, it'd be more like :

    PHP Code:
    this["sound"+var].start(0,999); 
    again, depending on how you are managing your Sound playing, timeline based or Sound object..

    gparis

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