dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Can strings be counted?

  1. #1

    Can strings be counted?

    I have a form with 10 groups of 3 radio buttons, each group of which has a string variable ("Regularly", "Sometimes", or "Never"). So, if you select "Regularly" for all 10 groups, there would be 10 instances of the variable "Regularly". Hopefully that makes sense.

    Is there any way to count the number of times any of those 3 string variables has been set upon submit, so as to show feedback that might say "You selected 'Regularly' 6 times"?
    Many thanks,
    Scott

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I think this is pretty complex but when you give evry radiobut a name you can make if statements if so and aso and so and so and so on has been selected. This looks to me like a long script at least at the first glance.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    The world goes - hm.. TheCaramella's Avatar
    Join Date
    Dec 2001
    Location
    Second door on the right, next to the ice bear
    Posts
    642
    Create a variable that increases each time f. i. the value Regular's been chosen, and one increasing variable for all the other values you want to count.

  4. #4
    Thanks for the help so far! I've been able to get a working solution using this code:

    //check radio1
    if (roller.radio1.getData()=="Regularly") {
    r1=5;
    }
    else if (roller.radio1.getData()=="Sometimes") {
    r1=3;
    }
    else if (roller.radio1.getData()=="Never") {
    r1=0;
    }
    //check radio2
    if (roller.radio2.getData()=="Regularly") {
    r2=5;
    }
    else if (roller.radio2.getData()=="Sometimes") {
    r2=3;
    }
    else if (roller.radio2.getData()=="Never") {
    r2=0;
    }
    //etc...through r10
    total=(r1+r2+r3+r4+r5+r6+r7+r8+r9+r10);

    It adds everything up to get the total I'm looking for, however, like cancerinform said, it's pretty code-heavy, even at 10 questions (I also need to do one that'll have 45!)

    I'm new to components--is there an easy way to assign numeric values to radio buttons, as well as a string variable? For example, the "data" value in the component properties of the 1st radio button in the group could be both "Regularly" (string) and r1=r1+5 (numeric), the second could be both "Sometimes" and r1=r1+3, and the third both "Never" and r1=r1+0. That way I can retrieve both the selection value (for a concatenated feedback) and the numeric count to get the total, which avoids a ton of if/then conditionals. It seems that the data value for radios gets interpreted only as a string, which prevents any counting of its variables if they're numbers.
    Many thanks,
    Scott

  5. #5
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I frankly don't know the answer. However you want to think about the parseInt function which converts strings to numbers:

    parseInt("10"); will return 10 as a number.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  6. #6
    OK, thanks. I tried Number(1) and it didn't work, but on the next page I missed the parseInt() section (I'm using Moock's book) .
    Many thanks,
    Scott

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